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

Commit d336d620 by Sascha Depold

Merge branch 'master' of github.com:sequelize/sequelize

2 parents ec2d5dd3 e68eb978
Showing with 23 additions and 7 deletions
......@@ -46,11 +46,15 @@ module.exports = (function() {
ConnectorManager.prototype.query = function(sql, callee, options) {
var self = this
// we really want pendingQueries to increment as fast as possible...
self.pendingQueries++
return new Utils.CustomEventEmitter(function(emitter) {
self.connect()
.on('error', function(err) {
// zero-out the previous increment
self.pendingQueries--
self.endQuery.call(self)
emitter.emit('error', err)
})
.on('success', function(done) {
......@@ -58,14 +62,22 @@ module.exports = (function() {
done = done || null
query.run(sql, done)
.success(function(results) { emitter.emit('success', results); self.endQuery.call(self) })
.error(function(err) { emitter.emit('error', err); self.endQuery.call(self) })
.success(function(results) {
self.pendingQueries--
emitter.emit('success', results)
self.endQuery.call(self)
})
.error(function(err) {
self.pendingQueries--
emitter.emit('error', err)
self.endQuery.call(self)
})
.on('sql', function(sql) { emitter.emit('sql', sql) })
})
}).run().complete(function() { self.pendingQueries-- })
}).run()
}
ConnectorManager.prototype.connect = function(callback) {
ConnectorManager.prototype.connect = function() {
var self = this
var emitter = new (require('events').EventEmitter)()
......@@ -119,9 +131,13 @@ module.exports = (function() {
this.poolIdentifier = this.pg.pools.getOrCreate(this.sequelize.config)
this.poolIdentifier.connect(connectCallback)
} else {
//create one-off client
this.client = new this.pg.Client(uri)
this.client.connect(connectCallback)
if (this.client !== null) {
connectCallback(null, this.client)
} else {
//create one-off client
this.client = new this.pg.Client(uri)
this.client.connect(connectCallback)
}
}
return emitter
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!