Connection Pool for tedious.
npm install tedious-connection-pool
A connection pool for tedious.
npm install tedious-connection-pool
Once the Tedious Connection object has been acquired, the tedious API can be used with the connection as normal.
``javascript
var ConnectionPool = require('tedious-connection-pool');
var Request = require('tedious').Request;
var poolConfig = {
min: 2,
max: 4,
log: true
};
var connectionConfig = {
userName: 'login',
password: 'password',
server: 'localhost'
};
//create the pool
var pool = new ConnectionPool(poolConfig, connectionConfig);
pool.on('error', function(err) {
console.error(err);
});
//acquire a connection
pool.acquire(function (err, connection) {
if (err) {
console.error(err);
return;
}
//use the connection as normal
var request = new Request('select 42', function(err, rowCount) {
if (err) {
console.error(err);
return;
}
console.log('rowCount: ' + rowCount);
//release the connection back to the pool when finished
connection.release();
});
request.on('row', function(columns) {
console.log('value: ' + columns[0].value);
});
connection.execSql(request);
});
`
When you are finished with the pool, you can drain it (close all connections).
`javascript`
pool.drain();
* poolConfig {Object} the pool configuration objectmin
* {Number} The minimun of connections there can be in the pool. Default = 10max
* {Number} The maximum number of connections there can be in the pool. Default = 50idleTimeout
* {Number} The number of milliseconds before closing an unused connection. Default = 300000retryDelay
* {Number} The number of milliseconds to wait after a connection fails, before trying again. Default = 5000acquireTimeout
* {Number} The number of milliseconds to wait for a connection, before returning an error. Default = 60000log
* {Boolean|Function} Set to true to have debug log written to the console or pass a function to receive the log messages. Default = undefinedconnectionConfig
* {Object} The same configuration that would be used to create a
tedious Connection.
* callback(err, connection) {Function} Callback functionerr
* {Object} An Error object is an error occurred trying to acquire a connection, otherwise null.connection
* {Object} A Connection