diff --git a/index.js b/index.js index ba511ef..5f376a2 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ module.exports = require('./lib/connection.js'); -module.exports.setConfig = require('./lib/connection.js').setConfig; module.exports.query = require('./lib/query.js'); module.exports.model = require('./lib/model.js'); module.exports.import = require('./lib/model.js').import; \ No newline at end of file diff --git a/lib/connection.js b/lib/connection.js index dd51b2b..70806f4 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -52,8 +52,13 @@ function _connectPool(pool, that, callback){ // connection functions for client pooling Redshift.prototype.close = function(callback){ var that = this; //store original context of this because it will change inside callbacks - if(that.connectionType && that.connectionType === 'client' && that.client) that.client.end(callback); - else if(that.connectionType && that.connectionType === 'pool' && that.pool) that.pool.end(); + if(that.connectionType && that.connectionType === 'client' && that.client){ + that.client.end(callback); + } + else if(that.connectionType && that.connectionType === 'pool' && that.pool){ + that.pool.end(callback); + delete that.pool; + } }; @@ -63,12 +68,17 @@ Redshift.prototype.connect = function(callback){ that.client.connect(callback); } else if(that.connectionType === 'pool'){ - var pool = new pg.Pool(that.config); + if(that.pool){ + callback(new Error("A connection pool already exists, can't call connect")); + } + else{ + var pool = new pg.Pool(that.config); - _connectPool(pool, that, function(err){ - if(err) callback(err); - else callback(); - }); + _connectPool(pool, that, function(err){ + if(err) callback(err); + else callback(); + }); + } } else callback(new Error("Couldn't connect to redshift. Invalid connection type")); }; diff --git a/lib/query.js b/lib/query.js index d12656c..d3ead0b 100644 --- a/lib/query.js +++ b/lib/query.js @@ -25,7 +25,7 @@ Redshift.prototype.query = function(query, options, callback){ count = count + 1; // count the attempts if(count > 600){ // and after 1 min, give up clearInterval(intId); - throw new Error("Taking too long to estable connection or unable to make query"); + throw new Error("Unable to establish connection to redshift"); } } }, 100);