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

Commit e6aefa7d by Sascha Depold

made abstract query more generic

1 parent f23b4dee
Showing with 24 additions and 4 deletions
...@@ -118,6 +118,15 @@ module.exports = (function() { ...@@ -118,6 +118,15 @@ module.exports = (function() {
return eval(fctName).apply(this, args) return eval(fctName).apply(this, args)
} }
/**
* Get the attributes of an insert query, which contains the just inserted id.
*
* @return {String} The field name.
*/
AbstractQuery.prototype.getInsertIdField = function() {
return 'insertId'
}
///////////// /////////////
// private // // private //
///////////// /////////////
...@@ -155,19 +164,30 @@ module.exports = (function() { ...@@ -155,19 +164,30 @@ module.exports = (function() {
return false return false
} }
var isInsertQuery = function(results) { var isInsertQuery = function(results, metaData) {
var result = true var result = true
// is insert query if sql contains insert into
result = result && (this.sql.toLowerCase().indexOf('insert into') === 0) result = result && (this.sql.toLowerCase().indexOf('insert into') === 0)
result = result && (!results || results.hasOwnProperty('insertId'))
// is insert query if no results are passed or if the result has the inserted id
result = result && (!results || results.hasOwnProperty(this.getInsertIdField()))
// is insert query if no metadata are passed or if the metadata has the inserted id
result = result && (!metaData || metaData.hasOwnProperty(this.getInsertIdField()))
return result return result
} }
var handleInsertQuery = function(results) { var handleInsertQuery = function(results, metaData) {
// add the inserted row id to the instance // add the inserted row id to the instance
var autoIncrementField = this.callee.__factory.autoIncrementField var autoIncrementField = this.callee.__factory.autoIncrementField
this.callee[autoIncrementField] = results.insertId , id = null
id = id || (results && results[this.getInsertIdField()])
id = id || (metaData && metaData[this.getInsertIdField()])
this.callee[autoIncrementField] = id
} }
var isShowTableQuery = function() { var isShowTableQuery = function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!