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

Commit f8772a82 by Sascha Depold

transaction support for daofactory#create

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