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

Commit d585c36a by Sascha Depold

Merge pull request #860 from durango/postgres-connection

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