不要怂,就是干,撸起袖子干!

Commit d585c36a by Sascha Depold

Merge pull request #860 from durango/postgres-connection

Fix: Postgres connection issues
2 parents 6832ccaf 97c50bee
...@@ -19,8 +19,9 @@ module.exports = (function() { ...@@ -19,8 +19,9 @@ module.exports = (function() {
// set pooling parameters if specified // set pooling parameters if specified
if (this.pooling) { if (this.pooling) {
this.pg.defaults.poolSize = this.config.pool.maxConnections this.pg.defaults.poolSize = this.config.pool.maxConnections
this.pg.defaults.poolIdleTimeout = this.config.pool.maxIdleTime this.pg.defaults.poolIdleTimeout = this.config.pool.maxIdleTime
this.pg.defaults.reapIntervalMillis = this.config.pool.reapInterval || 1000
} }
this.disconnectTimeoutId = null this.disconnectTimeoutId = null
...@@ -57,9 +58,9 @@ module.exports = (function() { ...@@ -57,9 +58,9 @@ module.exports = (function() {
}) })
.on('success', function(done) { .on('success', function(done) {
var query = new Query(self.client, self.sequelize, callee, options || {}) var query = new Query(self.client, self.sequelize, callee, options || {})
done = done || null
return query.run(sql, done) return query.run(sql)
.complete(function(err) { done && done(err) })
.success(function(results) { self.endQuery.call(self) }) .success(function(results) { self.endQuery.call(self) })
.error(function(err) { self.endQuery.call(self) }) .error(function(err) { self.endQuery.call(self) })
.proxy(emitter) .proxy(emitter)
...@@ -113,17 +114,17 @@ module.exports = (function() { ...@@ -113,17 +114,17 @@ module.exports = (function() {
emitter.emit('success', done) emitter.emit('success', done)
}) })
} else { } else {
done && done()
self.client = null self.client = null
emitter.emit('success', done) emitter.emit('success')
} }
} }
if (this.pooling) { if (this.pooling) {
// acquire client from pool // acquire client from pool
this.poolIdentifier = this.pg.pools.getOrCreate(uri) this.pg.connect(uri, connectCallback)
this.poolIdentifier.connect(connectCallback)
} else { } else {
if (!!this.client && this.client.readyForQuery === true) { if (!!this.client) {
connectCallback(null, this.client) connectCallback(null, this.client)
} else { } else {
//create one-off client //create one-off client
...@@ -141,10 +142,9 @@ module.exports = (function() { ...@@ -141,10 +142,9 @@ module.exports = (function() {
} }
if (this.client) { if (this.client) {
this.client.end() this.client.end.bind(this.client)
} }
this.client = null
this.isConnecting = false this.isConnecting = false
this.isConnected = false this.isConnected = false
} }
......
...@@ -18,7 +18,7 @@ module.exports = (function() { ...@@ -18,7 +18,7 @@ module.exports = (function() {
} }
Utils.inherit(Query, AbstractQuery) Utils.inherit(Query, AbstractQuery)
Query.prototype.run = function(sql, done) { Query.prototype.run = function(sql) {
this.sql = sql this.sql = sql
var self = this var self = this
...@@ -40,7 +40,6 @@ module.exports = (function() { ...@@ -40,7 +40,6 @@ module.exports = (function() {
}.bind(this)) }.bind(this))
query.on('end', function() { query.on('end', function() {
done && done()
this.emit('sql', this.sql) this.emit('sql', this.sql)
if (receivedError) { if (receivedError) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!