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

Commit 270ac753 by Daniel Durante

Fixes PostgresSQL connection problems.

This commit fixes the following connection problems:
* Pools should now properly release themselves always
* You can now set a "TestOnBorrow"-like functionality with
  config.pool.reapInterval).
* Heroku should be able to properly send the correct DB credentials.
1 parent c2d59e20
......@@ -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,6 +114,7 @@ module.exports = (function() {
emitter.emit('success', done)
})
} else {
done && done()
self.client = null
emitter.emit('success', done)
}
......@@ -120,8 +122,7 @@ module.exports = (function() {
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) {
connectCallback(null, this.client)
......
......@@ -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!