forked from martintajur/node-mysql-activerecord
-
Notifications
You must be signed in to change notification settings - Fork 19
Closed
Labels
Milestone
Description
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