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

Commit 7968f093 by Sascha Depold

sqlite query is almost eager-loading compatible

1 parent e6aefa7d
Showing with 16 additions and 16 deletions
......@@ -16,6 +16,10 @@ module.exports = (function() {
}
Utils.inherit(Query, AbstractQuery)
Query.prototype.getInsertIdField = function() {
return 'lastID'
}
Query.prototype.run = function(sql) {
var self = this
......@@ -75,34 +79,30 @@ module.exports = (function() {
, self = this
// add the inserted row id to the instance
if (this.callee && (this.sql.indexOf('INSERT INTO') == 0) && metaData.hasOwnProperty('lastID')) {
var autoIncrementField = this.callee.__factory.autoIncrementField
this.callee[autoIncrementField] = metaData.lastID
if (this.send('isInsertQuery', results, metaData)) {
this.send('handleInsertQuery', results, metaData)
}
if (this.sql.indexOf('sqlite_master') != -1) {
result = results.map(function(resultSet){ return resultSet.name })
} else if (this.sql.indexOf('SELECT') == 0) {
// transform results into real model instances
// return the first real model instance if options.plain is set (e.g. Model.find)
result = results.map(function(resultSet) { return resultSet.name })
} else if (this.send('isSelectQuery')) {
// we need to convert the timestamps into actual date objects
if(this.options.raw) {
result = results
} else {
result = results.map(function(result) {
if(!this.options.raw) {
results = results.map(function(result) {
for (var name in result) {
if (metaData.columnTypes[name] === 'DATETIME') {
if (result.hasOwnProperty(name) && (metaData.columnTypes[name] === 'DATETIME')) {
result[name] = new Date(result[name]);
}
}
return self.callee.build(result, { isNewRecord: false })
return result
})
}
if(this.options.plain)
result = (result.length == 0) ? null : result[0]
} else if((this.sql.indexOf('SHOW') == 0) || (this.sql.indexOf('DESCRIBE') == 0))
result = this.send('handleSelectQuery', results)
} else if (this.send('isShowOrDescribeQuery')) {
result = results
}
this.emit('success', result)
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!