diff --git a/.gitignore b/.gitignore index 81d95c881..ad9f77fa3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules/ *.log .lock-wscript build/ +.DS_Store diff --git a/lib/index.js b/lib/index.js index 9dcf7c173..3e75b1860 100644 --- a/lib/index.js +++ b/lib/index.js @@ -42,11 +42,15 @@ PG.prototype.connect = function(config, callback) { var poolName = typeof(c) === 'string' ? c : c.user+c.host+c.port+c.database; var pool = pools[poolName]; - if(pool) return pool.acquire(cb); + if(pool) { + // console.log("pg: pool:", pool.getName(), pool.getPoolSize(), pool.availableObjectsCount(), pool.waitingClientsCount()); + return pool.acquire(cb); + } var pool = pools[poolName] = genericPool.Pool({ name: poolName, create: function(callback) { + // console.log("pg: create connection"); var client = new self.Client(c); client.connect(function(err) { if(err) return callback(err); @@ -66,6 +70,7 @@ PG.prototype.connect = function(config, callback) { }); }, destroy: function(client) { + // console.log("pg: destroy connection"); client.end(); }, max: defaults.poolSize, @@ -95,3 +100,15 @@ module.exports.__defineGetter__("native", function() { }); module.exports.types = require('./types'); + +module.exports.stats = function(config) { + var pool = pools[config]; + if (pool) { + return { + size: pool.getPoolSize(), + available: pool.availableObjectsCount(), + waiting: pool.waitingClientsCount() + } + } + return null; +}