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

Commit 4189f2b0 by Sascha Depold

return the results when handling select queries

1 parent 5abd105c
Showing with 13 additions and 5 deletions
var Utils = require("./utils")
var Query = module.exports = function(databaseConfig, callee) {
var Query = module.exports = function(databaseConfig, callee, options) {
this.config = databaseConfig
this.callee = callee
this.options = options
}
Utils.addEventEmitter(Query)
......@@ -18,13 +19,20 @@ Query.prototype.run = function(query) {
console.log('Executing: ' + query)
client.connect()
client.query(query, function(err, info) {
client.query(query, function(err, results, fields) {
if(err) {
self.emit('failure', err, self.callee)
} else {
if (self.callee && (query.indexOf('INSERT INTO') == 0) && (info.hasOwnProperty('insertId')))
self.callee.id = info.insertId
self.emit('success', self.callee)
var result = self.callee
if (self.callee && (query.indexOf('INSERT INTO') == 0) && (results.hasOwnProperty('insertId')))
self.callee.id = results.insertId
if (query.indexOf('SELECT') == 0) {
// will transform result into models
result = results.map(function(result) { return self.callee.build(result) })
}
self.emit('success', result)
}
})
client.end()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!