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

Commit 9cd22912 by Bryan Tong

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

2 parents 7d2c7de4 c63ccaf6
...@@ -1130,10 +1130,15 @@ module.exports = (function() { ...@@ -1130,10 +1130,15 @@ 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. * @param {Boolean} value A boolean that states whether autocommit shall be done or not.
* @return {String} The generated sql query. * @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) + ';'; return 'SET autocommit = ' + (!!value ? 1 : 0) + ';';
}, },
......
...@@ -256,15 +256,24 @@ module.exports = (function() { ...@@ -256,15 +256,24 @@ module.exports = (function() {
parent: err parent: err
}); });
case '23505': 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
return new sequelizeErrors.UniqueConstraintError({ match = err.detail.match(/Key \((.*?)\)=\((.*?)\)/);
fields: match[1].split(', '),
value: match[2].split(', '), if (match) {
index: null, return new sequelizeErrors.UniqueConstraintError({
parent: err fields: match[1].split(', '),
}); value: match[2].split(', '),
index: null,
parent: err
});
} else {
return new sequelizeErrors.UniqueConstraintError({
error: err,
message: err.message
});
}
break;
default: default:
return new sequelizeErrors.DatabaseError(err); return new sequelizeErrors.DatabaseError(err);
} }
......
...@@ -712,13 +712,21 @@ module.exports = (function() { ...@@ -712,13 +712,21 @@ module.exports = (function() {
return this.QueryGenerator.escape(value); return this.QueryGenerator.escape(value);
}; };
QueryInterface.prototype.setAutocommit = function(transaction, value) { QueryInterface.prototype.setAutocommit = function(transaction, value, options) {
if (!transaction || !(transaction instanceof Transaction)) { if (!transaction || !(transaction instanceof Transaction)) {
throw new Error('Unable to set autocommit for a transaction without transaction object!'); throw new Error('Unable to set autocommit for a transaction without transaction object!');
} }
var sql = this.QueryGenerator.setAutocommitQuery(value); options = Utils._.extend({
return this.sequelize.query(sql, null, { transaction: transaction}); 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) { QueryInterface.prototype.setIsolationLevel = function(transaction, value, options) {
......
...@@ -136,7 +136,7 @@ Transaction.prototype.setAutocommit = function() { ...@@ -136,7 +136,7 @@ Transaction.prototype.setAutocommit = function() {
return this return this
.sequelize .sequelize
.getQueryInterface() .getQueryInterface()
.setAutocommit(this, this.options.autocommit); .setAutocommit(this, this.options.autocommit, this.options);
}; };
Transaction.prototype.setIsolationLevel = function() { 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!