forked from brianc/node-postgres
- Notifications
You must be signed in to change notification settings - Fork 0
chilts edited this page Feb 23, 2013
·
2 revisions
node-postgres can maintain client pools internally. They are generally accessed via pg#wiki-method-connect but can be directly accessed & manipulated via pg.pools.
A hash of all existing client pools. A pool's key is built by calling JSON.stringify on the first parameter passed to pg.connect unless the first parameter is a callback, in which case JSON.stringify({}) is used.
####example
varpg=require('pg');console.log(Object.keys(pg.pools.all));//[]//connect using defaults or environment variables//will create a pool by the name of "{}"pg.connect(function(err,client,done){done();console.log(Object.keys(pg.pools.all));//["{}"]});Gets a pool by the given key or creates it if it does not yet exist. In either case it returns a modified instance of https://github.com/coopernurse/node-pool pre-configured to return Client instances.
varpg=require('pg');pg.connect(function(err,client,done){varpool=pg.pools.getOrCreate();console.log(pool.getPoolSize());//1console.log(pool.availableObjectsCount());//0done();console.log(pool.getPoolSize());//1console.log(pool.availableObjectsCount());//1});