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

Commit f8772a82 by Sascha Depold

transaction support for daofactory#create

1 parent d546f80d
......@@ -539,6 +539,10 @@ module.exports = (function() {
fieldsOrOptions = { fields: fieldsOrOptions }
}
fieldsOrOptions = Utils._.extend({
transaction: null
}, fieldsOrOptions || {})
return this.build(values).save(fieldsOrOptions)
}
......
......@@ -177,7 +177,7 @@ module.exports = (function() {
if (self.isNewRecord) {
self.isDirty = false
query = 'insert'
args = [self, self.QueryInterface.QueryGenerator.addSchema(self.__factory), values]
args = [self, self.QueryInterface.QueryGenerator.addSchema(self.__factory), values, options]
hook = 'Create'
} else {
var identifier = self.__options.hasPrimaryKeys ? self.primaryKeyValues : { id: self.id }
......
......@@ -444,10 +444,11 @@ module.exports = (function() {
return queryAndEmit.call(this, sql, "removeIndex")
}
QueryInterface.prototype.insert = function(dao, tableName, values) {
QueryInterface.prototype.insert = function(dao, tableName, values, options) {
var sql = this.QueryGenerator.insertQuery(tableName, values, dao.daoFactory.rawAttributes)
return queryAndEmit.call(this, [sql, dao], 'insert', {
success: function(obj) { obj.isNewRecord = false }
success: function(obj) { obj.isNewRecord = false },
transaction: (options || {}).transaction
})
}
......@@ -870,7 +871,8 @@ module.exports = (function() {
var queryAndEmit = QueryInterface.prototype.queryAndEmit = function(sqlOrQueryParams, methodName, options, emitter) {
options = Utils._.extend({
success: function(){},
error: function(){}
error: function(){},
transaction: null
}, options || {})
var execQuery = function(emitter) {
......@@ -885,9 +887,11 @@ module.exports = (function() {
sqlOrQueryParams.push({})
}
sqlOrQueryParams[2].transaction = options.transaction
emitter.query = this.sequelize.query.apply(this.sequelize, sqlOrQueryParams)
} else {
emitter.query = this.sequelize.query(sqlOrQueryParams, null, {})
emitter.query = this.sequelize.query(sqlOrQueryParams, null, { transaction: options.transaction })
}
emitter
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!