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

Commit a5ed5fec by Sascha Depold

allow set of autocomment

1 parent 2efbe849
...@@ -457,6 +457,16 @@ module.exports = (function() { ...@@ -457,6 +457,16 @@ module.exports = (function() {
/** /**
* Returns a query that starts a transaction. * Returns a query that starts a transaction.
* *
* @param {Boolean} value A boolean that states whether autocommit shall be done or not.
* @return {String} The generated sql query.
*/
setAutocommitQuery: function(value) {
throwMethodUndefined('setAutocommitQuery')
},
/**
* Returns a query that starts a transaction.
*
* @param {Object} options An object with options. * @param {Object} options An object with options.
* @return {String} The generated sql query. * @return {String} The generated sql query.
*/ */
......
...@@ -330,6 +330,16 @@ module.exports = (function() { ...@@ -330,6 +330,16 @@ module.exports = (function() {
/** /**
* Returns a query that starts a transaction. * Returns a query that starts a transaction.
* *
* @param {Boolean} value A boolean that states whether autocommit shall be done or not.
* @return {String} The generated sql query.
*/
setAutocommitQuery: function(value) {
return "SET autocommit = " + (!!value ? 1 : 0) + ";"
},
/**
* Returns a query that starts a transaction.
*
* @param {Object} options An object with options. * @param {Object} options An object with options.
* @return {String} The generated sql query. * @return {String} The generated sql query.
*/ */
......
...@@ -799,6 +799,15 @@ module.exports = (function() { ...@@ -799,6 +799,15 @@ module.exports = (function() {
return this.QueryGenerator.escape(value) return this.QueryGenerator.escape(value)
} }
QueryInterface.prototype.setAutocommit = function(transaction, value) {
if (!transaction || !(transaction instanceof Transaction)) {
throw new Error('Unable to set autocommit for a transaction without transaction object!')
}
var sql = this.QueryGenerator.setAutocommitQuery(value)
return this.queryAndEmit([sql, null, { transaction: transaction }], 'setAutocommit')
}
QueryInterface.prototype.startTransaction = function(transaction, options) { QueryInterface.prototype.startTransaction = function(transaction, options) {
if (!transaction || !(transaction instanceof Transaction)) { if (!transaction || !(transaction instanceof Transaction)) {
throw new Error('Unable to start a transaction without transaction object!') throw new Error('Unable to start a transaction without transaction object!')
......
...@@ -393,13 +393,28 @@ module.exports = (function() { ...@@ -393,13 +393,28 @@ module.exports = (function() {
, transaction = new Transaction(this, options) , transaction = new Transaction(this, options)
, self = this , self = this
Utils.tick(function() { var startTransaction = function() {
self self
.getQueryInterface() .getQueryInterface()
.startTransaction(transaction, {}) .startTransaction(transaction, {})
.success(function() { .success(function() {
callback(transaction) callback(transaction)
}) })
}
var setAutocommit = function(value, cb) {
self
.getQueryInterface()
.setAutocommit(transaction, value)
.success(cb)
}
Utils.tick(function() {
if (options.hasOwnProperty('autocommit')) {
setAutocommit(!!options.autocommit, startTransaction)
} else {
startTransaction()
}
}) })
return transaction return transaction
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!