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

Commit 9cd22912 by Bryan Tong

Merge branch 'master' of https://github.com/sequelize/sequelize

2 parents 7d2c7de4 c63ccaf6
......@@ -1131,9 +1131,14 @@ module.exports = (function() {
* Returns a query that starts a transaction.
*
* @param {Boolean} value A boolean that states whether autocommit shall be done or not.
* @param {Object} options An object with options.
* @return {String} The generated sql query.
*/
setAutocommitQuery: function(value) {
setAutocommitQuery: function(value, options) {
if (options.parent) {
return;
}
return 'SET autocommit = ' + (!!value ? 1 : 0) + ';';
},
......
......@@ -256,15 +256,24 @@ module.exports = (function() {
parent: err
});
case '23505':
match = err.detail.match(/Key \((.*?)\)=\((.*?)\) already exists/);
// there are multiple different formats of error messages for this error code
// this regex should check at least two
match = err.detail.match(/Key \((.*?)\)=\((.*?)\)/);
if (match) {
return new sequelizeErrors.UniqueConstraintError({
fields: match[1].split(', '),
value: match[2].split(', '),
index: null,
parent: err
});
} else {
return new sequelizeErrors.UniqueConstraintError({
error: err,
message: err.message
});
}
break;
default:
return new sequelizeErrors.DatabaseError(err);
}
......
......@@ -712,13 +712,21 @@ module.exports = (function() {
return this.QueryGenerator.escape(value);
};
QueryInterface.prototype.setAutocommit = function(transaction, value) {
QueryInterface.prototype.setAutocommit = function(transaction, value, options) {
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.sequelize.query(sql, null, { transaction: transaction});
options = Utils._.extend({
parent: options.transaction
}, options || {});
var sql = this.QueryGenerator.setAutocommitQuery(value, options);
if (sql) {
return this.sequelize.query(sql, null, { transaction: transaction });
} else {
return Utils.Promise.resolve();
}
};
QueryInterface.prototype.setIsolationLevel = function(transaction, value, options) {
......
......@@ -136,7 +136,7 @@ Transaction.prototype.setAutocommit = function() {
return this
.sequelize
.getQueryInterface()
.setAutocommit(this, this.options.autocommit);
.setAutocommit(this, this.options.autocommit, this.options);
};
Transaction.prototype.setIsolationLevel = function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!