Connection pool tweak
rodzic
8d61c08320
commit
deffe91eaa
|
@ -1,7 +1,7 @@
|
||||||
var mariadb = require('mariadb');
|
var mariadb = require('mariadb');
|
||||||
|
|
||||||
var configs = [
|
var pools = [
|
||||||
{
|
mariadb.createPool({
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
user:'root',
|
user:'root',
|
||||||
password: 'password',
|
password: 'password',
|
||||||
|
@ -9,8 +9,8 @@ var configs = [
|
||||||
port: 3309,
|
port: 3309,
|
||||||
multipleStatements: true,
|
multipleStatements: true,
|
||||||
connectionLimit: 5
|
connectionLimit: 5
|
||||||
},
|
}),
|
||||||
{
|
mariadb.createPool({
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
user:'root',
|
user:'root',
|
||||||
password: 'password',
|
password: 'password',
|
||||||
|
@ -18,18 +18,13 @@ var configs = [
|
||||||
port: 3310,
|
port: 3310,
|
||||||
multipleStatements: true,
|
multipleStatements: true,
|
||||||
connectionLimit: 5
|
connectionLimit: 5
|
||||||
}
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
function getPool(config) {
|
|
||||||
return mariadb.createPool(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports={
|
module.exports={
|
||||||
getConnection: function(config_id){
|
getConnection: function(config_id){
|
||||||
console.log(config_id);
|
|
||||||
return new Promise(function(resolve,reject){
|
return new Promise(function(resolve,reject){
|
||||||
getPool(configs[config_id]).getConnection().then(function(connection){
|
pools[config_id].getConnection().then(function(connection){
|
||||||
resolve(connection);
|
resolve(connection);
|
||||||
}).catch(function(error){
|
}).catch(function(error){
|
||||||
reject(error);
|
reject(error);
|
||||||
|
|
Ładowanie…
Reference in New Issue