Skip to content

Commit

Permalink
Merge pull request sequelize#860 from durango/postgres-connection
Browse files Browse the repository at this point in the history
Fix: Postgres connection issues
  • Loading branch information
sdepold committed Aug 30, 2013
2 parents 6832cca + 97c50be commit d585c36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
20 changes: 10 additions & 10 deletions lib/dialects/postgres/connector-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ module.exports = (function() {

// set pooling parameters if specified
if (this.pooling) {
this.pg.defaults.poolSize = this.config.pool.maxConnections
this.pg.defaults.poolIdleTimeout = this.config.pool.maxIdleTime
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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions lib/dialects/postgres/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -40,7 +40,6 @@ module.exports = (function() {
}.bind(this))

query.on('end', function() {
done && done()
this.emit('sql', this.sql)

if (receivedError) {
Expand Down

0 comments on commit d585c36

Please sign in to comment.