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

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() { ...@@ -21,6 +21,7 @@ module.exports = (function() {
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,6 +114,7 @@ module.exports = (function() { ...@@ -113,6 +114,7 @@ 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', done)
} }
...@@ -120,8 +122,7 @@ module.exports = (function() { ...@@ -120,8 +122,7 @@ module.exports = (function() {
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 && this.client.readyForQuery === true) {
connectCallback(null, this.client) connectCallback(null, this.client)
......
...@@ -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!