Skip to content

Commit

Permalink
Add example and API details to readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekim committed Oct 7, 2012
1 parent a8a5a51 commit 5c48770
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions README.md
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)

0 comments on commit 5c48770

Please sign in to comment.