Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrent Use of Two Pools and Two Databases #18

Closed
dustinmolieri opened this issue Dec 20, 2017 · 7 comments
Closed

Concurrent Use of Two Pools and Two Databases #18

dustinmolieri opened this issue Dec 20, 2017 · 7 comments
Milestone

Comments

@dustinmolieri
Copy link

dustinmolieri commented Dec 20, 2017

Issue: connection_settings for one pool are lost when setting up another pool

Snippet:

// Connects to database_a on localhost
const AsqlSettings = {
    host: '127.0.0.1',
    database: 'myuser',
    user: 'mypassword',
    password: 'database_a',
    pool_size: 20
}

// Connects to database_b on localhost
const BsqlSettings = {
    host: '127.0.0.1',
    database: 'myuser',
    user: 'mypassword',
    password: 'database_b',
    pool_size: 20
}

// Pool for database_a is declared
var APool = require('node-querybuilder').QueryBuilder(AsqlSettings, 'mysql', 'pool');

// pool for database_b is declared
var BPool = require('node-querybuilder').QueryBuilder(BsqlSettings, 'mysql', 'pool');

// database_a is queried, but returns error because "database_b.tableABC" does not exist
// and it shouldn't be suing database_b, it should be using database_a based on settings
APool.get_connection(function(qb){
    qb.select(['field1','field2']).get('tableABC', (err,response) => {
       // optionally do:
       // console.log(qb.connection_settings());
       // here, you will see its not using AsqlSettings, but rather BsqlSettings
       // and connecting to database_b not database_a despite being APool
        qb.release();
        if(err) { console.error(err); return; }
        for (const i in response) {
            const row = response[i];
            console.log(row['field1']);
            console.log(row['field2']);
        }    
    });
});

// has no issues, since this pool's connection settings were retained
BPool.get_connection(function(qb){
    qb.select(['fieldX','fieldY']).get('table123', (err,response) => {
        qb.release();
        if(err){ console.error(err); return; }
        for (const i in response) {
            const row = response[i];
            console.log(row['fieldX']);
            console.log(row['fieldY']);
        }    
    });
});`

Effect of this bug:
Cannot use multiple databases in the same JS, such as one for authentication and another for data

@kylefarris
Copy link
Owner

Interesting. I can take a look next week, after the holidays.

@dustinmolieri
Copy link
Author

BUMP

@dustinmolieri
Copy link
Author

Any Update?

@kylefarris
Copy link
Owner

Sorry Dustin, I simply don't have time at the moment. I'm open to a Pull Request if you're up to the task of find the issue and solving it.

@selfclose
Copy link

Bump, I need this as well :)

@kylefarris
Copy link
Owner

FWIW, I'm working on getting this to work in v2 which should be released in the early part of August (or earlier). It will come with a few breaking changes (mostly because it requires at least Node version 8.0+).

I'll let you know when the beta is out so you can test it out.

kylefarris pushed a commit that referenced this issue Jul 25, 2018
… credentials and updated all files using credentials to use that instead.
@kylefarris
Copy link
Owner

This is officially fixed in the v2 branch. Beta should be out soon.

kylefarris pushed a commit that referenced this issue Feb 1, 2019
… credentials and updated all files using credentials to use that instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants