forked from tediousjs/tedious-connection-pool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example and API details to readme.
- Loading branch information
Showing
1 changed file
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,49 @@ | ||
tedious-connection-pool | ||
======================= | ||
# tedious-connection-pool | ||
A simple connection pool for [tedious](http://github.com/pekim/tedious). | ||
|
||
## Example | ||
The only difference from the regular tedious API is how the connection is obtained. | ||
Once a Connection object has been acquired, the tedious API can be used with the | ||
connection as normal. | ||
|
||
```javascript | ||
var ConnectionPool = require('tedious-connection-pool'); | ||
|
||
var pool = new ConnectionPool(poolConfig, connectionConfig); | ||
|
||
pool.requestConnection(function (connection) { | ||
var request = new Request('select 42', function(err, rowCount) { | ||
assert.strictEqual(rowCount, 1); | ||
|
||
// Release the connection back to the pool. | ||
connection.close(); | ||
}); | ||
|
||
request.on('row', function(columns) { | ||
assert.strictEqual(columns[0].value, 42); | ||
}); | ||
|
||
connection.on('connect', function(err) { | ||
connection.execSql(request); | ||
}); | ||
}); | ||
``` | ||
|
||
When the connection is closed it is returned to the pool. | ||
It is then available to be reused. | ||
|
||
##Class: ConnectionPool | ||
|
||
### new ConnectionPool(poolConfig, connectionConfig) | ||
|
||
* `poolConfig` {Object} | ||
* `maxSize` {Number} The maximum number of connections there can be in the pool. | ||
Default = `10` | ||
* `connectionConfig` {Object} The same configuration that would be used to [create a | ||
tedious Connection](http://pekim.github.com/tedious/api-connection.html#function_newConnection). | ||
|
||
### connectionPool.requestConnection(callback) | ||
|
||
* `callback` {Function} Callback function | ||
* `error` {Error Object} | ||
* `connection` {Object} A [Connection](http://pekim.github.com/tedious/api-connection.html) |