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

Commit d590fe20 by Sascha Depold

use the stored sql instead of passing it to the function

1 parent b9820b7d
Showing with 7 additions and 6 deletions
......@@ -14,9 +14,10 @@ module.exports = (function() {
}
Utils.addEventEmitter(Query)
Query.prototype.run = function(query) {
Query.prototype.run = function(sql) {
var self = this
this.sql = query
this.sql = sql
bindClient.call(this)
......@@ -24,7 +25,7 @@ module.exports = (function() {
console.log('Executing: ' + this.sql)
this.client.query(this.sql, function(err, results, fields) {
err ? onFailure.call(self, err) : onSuccess.call(self, self.sql, results, fields)
err ? onFailure.call(self, err) : onSuccess.call(self, results, fields)
}).setMaxListeners(100)
return this
......@@ -50,17 +51,17 @@ module.exports = (function() {
this.client.removeListener('error', this.bindClientFunction)
}
var onSuccess = function(query, results, fields) {
var onSuccess = function(results, fields) {
var result = this.callee
, self = this
// add the inserted row id to the instance
if (this.callee && (query.indexOf('INSERT INTO') == 0) && (results.hasOwnProperty('insertId')))
if (this.callee && (this.sql.indexOf('INSERT INTO') == 0) && (results.hasOwnProperty('insertId')))
this.callee[this.callee.__definition.autoIncrementField] = results.insertId
// transform results into real model instances
// return the first real model instance if options.plain is set (e.g. Model.find)
if (query.indexOf('SELECT') == 0) {
if (this.sql.indexOf('SELECT') == 0) {
result = results.map(function(result) { return self.callee.build(result, {isNewRecord: false}) })
if(this.options.plain)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!