sheng-tedious-connection-pool
v1.0.3
Published
this library is a modification to current tedious-connection-pool libary, make it works to use the newest tedious library. The usage of this library has slightly difference, in order to make sure each application only initialize one pool for each database
Downloads
2
Maintainers
Readme
How to use: 1, create a pool.js similar with following code, make sure your node app only execute one instance of ConnectionPool
const poolConfig = {
min: 2,
max: 4,
log: true
};
const connectionConfig = {
server: 'http://database_server:14337',
authentication: {
type: 'default',
options: {
userName: USER,
password: PASSWORD,
},
},
options: {
trustServerCertificate: true,
database: DATABASE,
instanceName: INSTANCE,
},
};
export const dbPoolFunc = () => {
const dbpoolInstance = new ConnectionPool(
poolConfig,
connectionConfig,
);
dbpoolInstance.connect();
return dbpoolInstance;
};
export const dbPool = dbPoolFunc();
2, Use the pool instance to execute your queries
dbPoolInstance.acquire(function (error, connection) {
if (error) {
console.error(error);
return;
}
const request = new Request(queryStr, (err) => {
if (err) {
reject(`Request error: ${err.message}`);
}
resolve(result);
});
......
connection.on('connect', (err) => {
if (err) {
reject(err);
} else {
connection.execSql(request);
}
});
//should trigger connect method after 'Connecting' done
if (connection.state && connection.state.name !== 'Connecting') {
connection.connect();
}