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

Commit 68d5e45f by Sascha Depold

minor cleanup

1 parent 9419770e
Showing with 11 additions and 15 deletions
......@@ -13,7 +13,6 @@ module.exports = (function() {
}, options || {})
this.checkLoggingOption()
this.bindClientFunction = function(err) { onFailure.call(this, err) }.bind(this)
}
Utils.inherit(Query, AbstractQuery)
......@@ -28,16 +27,18 @@ module.exports = (function() {
}
this.client.query(this.sql, function(err, results, fields) {
unbindClient.call(this)
this.emit('sql', this.sql)
if (err) {
onFailure.call(this, err)
this.emit('error', err, this.callee)
} else {
if (Array.isArray(results) && !!results[0] && Utils._.keys(results[0]).length === 1) {
results = results.map(function(result){ return Utils._.values(result)[0] })
}
onSuccess.call(this, results, fields)
this.emit('success', this.formatResults(results))
}
}.bind(this)).setMaxListeners(100)
......@@ -46,22 +47,17 @@ module.exports = (function() {
//private
var bindClient = function() {
this.client.on('error', this.bindClientFunction)
}
var unbindClient = function() {
this.client.removeListener('error', this.bindClientFunction)
var onClientError = function(err) {
unbindClient.call(this)
this.emit('error', err, this.callee)
}
var onSuccess = function(results, fields) {
unbindClient.call(this)
this.emit('success', this.formatResults(results))
var bindClient = function() {
this.client.on('error', onClientError.bind(this))
}
var onFailure = function(err) {
unbindClient.call(this)
this.emit('error', err, this.callee)
var unbindClient = function() {
this.client.removeListener('error', onClientError.bind(this))
}
return Query
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!