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

Commit ee9ec57d by Takashi Sasaki Committed by Sushant

refactor(transaction): remove autocommit mode (#9921)

1 parent 98afe2e9
...@@ -176,7 +176,6 @@ The following options (with their default values) are available: ...@@ -176,7 +176,6 @@ The following options (with their default values) are available:
```js ```js
{ {
autocommit: true,
isolationLevel: 'REPEATABLE_READ', isolationLevel: 'REPEATABLE_READ',
deferrable: 'NOT DEFERRABLE' // implicit default of postgres deferrable: 'NOT DEFERRABLE' // implicit default of postgres
} }
......
...@@ -4,27 +4,6 @@ const uuidv4 = require('uuid/v4'); ...@@ -4,27 +4,6 @@ const uuidv4 = require('uuid/v4');
const TransactionQueries = { const TransactionQueries = {
/** /**
* 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.
* @returns {string} The generated sql query.
* @private
*/
setAutocommitQuery(value, options) {
if (options.parent) {
return;
}
// no query when value is not explicitly set
if (typeof value === 'undefined' || value === null) {
return;
}
return `SET autocommit = ${(value ? 1 : 0)};`;
},
/**
* Returns a query that sets the transaction isolation level. * Returns a query that sets the transaction isolation level.
* *
* @param {string} value The isolation level. * @param {string} value The isolation level.
......
...@@ -795,10 +795,6 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator { ...@@ -795,10 +795,6 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator {
}); });
} }
setAutocommitQuery() {
return '';
}
setIsolationLevelQuery() { setIsolationLevelQuery() {
} }
......
...@@ -906,25 +906,6 @@ class PostgresQueryGenerator extends AbstractQueryGenerator { ...@@ -906,25 +906,6 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
dropForeignKeyQuery(tableName, foreignKey) { dropForeignKeyQuery(tableName, foreignKey) {
return 'ALTER TABLE ' + this.quoteTable(tableName) + ' DROP CONSTRAINT ' + this.quoteIdentifier(foreignKey) + ';'; return 'ALTER TABLE ' + this.quoteTable(tableName) + ' DROP CONSTRAINT ' + this.quoteIdentifier(foreignKey) + ';';
} }
setAutocommitQuery(value, options) {
if (options.parent) {
return;
}
// POSTGRES does not support setting AUTOCOMMIT = OFF as of 9.4.0
// Additionally it does not support AUTOCOMMIT at all starting at v9.5
// The assumption is that it won't be returning in future versions either
// If you are on a Pg version that is not semver compliant e.g. '9.5.0beta2', which fails due to the 'beta' qualification, then you need to pass
// the database version as "9.5.0" explicitly through the options param passed when creating the Sequelize instance under the key "databaseVersion"
// otherwise Pg version "9.4.0" is assumed by default as per Sequelize 3.14.2.
// For Pg versions that are semver compliant, this is auto-detected upon the first connection.
if (!value || semver.gte(this.sequelize.options.databaseVersion, '9.4.0')) {
return;
}
return super.setAutocommitQuery.call(this, value, options);
}
}; };
module.exports = PostgresQueryGenerator; module.exports = PostgresQueryGenerator;
...@@ -31,8 +31,7 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype ...@@ -31,8 +31,7 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype
where: true where: true
}, },
transactionOptions: { transactionOptions: {
type: true, type: true
autocommit: false
}, },
constraints: { constraints: {
addConstraint: false, addConstraint: false,
......
...@@ -468,11 +468,6 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator { ...@@ -468,11 +468,6 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator {
return 'BEGIN ' + transaction.options.type + ' TRANSACTION;'; return 'BEGIN ' + transaction.options.type + ' TRANSACTION;';
} }
setAutocommitQuery() {
// SQLite does not support SET autocommit
return null;
}
setIsolationLevelQuery(value) { setIsolationLevelQuery(value) {
switch (value) { switch (value) {
case Transaction.ISOLATION_LEVELS.REPEATABLE_READ: case Transaction.ISOLATION_LEVELS.REPEATABLE_READ:
......
...@@ -1297,28 +1297,6 @@ class QueryInterface { ...@@ -1297,28 +1297,6 @@ class QueryInterface {
return this.QueryGenerator.escape(value); return this.QueryGenerator.escape(value);
} }
setAutocommit(transaction, value, options) {
if (!transaction || !(transaction instanceof Transaction)) {
throw new Error('Unable to set autocommit for a transaction without transaction object!');
}
if (transaction.parent) {
// Not possible to set a separate isolation level for savepoints
return Promise.resolve();
}
options = _.assign({}, options, {
transaction: transaction.parent || transaction
});
const sql = this.QueryGenerator.setAutocommitQuery(value, {
parent: transaction.parent
});
if (!sql) return Promise.resolve();
return this.sequelize.query(sql, options);
}
setIsolationLevel(transaction, value, options) { setIsolationLevel(transaction, value, options) {
if (!transaction || !(transaction instanceof Transaction)) { if (!transaction || !(transaction instanceof Transaction)) {
throw new Error('Unable to set isolation level for a transaction without transaction object!'); throw new Error('Unable to set isolation level for a transaction without transaction object!');
......
...@@ -982,7 +982,6 @@ class Sequelize { ...@@ -982,7 +982,6 @@ class Sequelize {
* // Note, that CLS is enabled for all sequelize instances, and all instances will share the same namespace * // Note, that CLS is enabled for all sequelize instances, and all instances will share the same namespace
* *
* @param {Object} [options] Transaction options * @param {Object} [options] Transaction options
* @param {boolean} [options.autocommit] Auto commit this transaction
* @param {string} [options.type='DEFERRED'] See `Sequelize.Transaction.TYPES` for possible options. Sqlite only. * @param {string} [options.type='DEFERRED'] See `Sequelize.Transaction.TYPES` for possible options. Sqlite only.
* @param {string} [options.isolationLevel] See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options * @param {string} [options.isolationLevel] See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql. * @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
......
...@@ -17,7 +17,6 @@ class Transaction { ...@@ -17,7 +17,6 @@ class Transaction {
* *
* @param {Sequelize} sequelize A configured sequelize Instance * @param {Sequelize} sequelize A configured sequelize Instance
* @param {Object} options An object with options * @param {Object} options An object with options
* @param {boolean} options.autocommit Sets the autocommit property of the transaction.
* @param {string} options.type=true Sets the type of the transaction. * @param {string} options.type=true Sets the type of the transaction.
* @param {string} options.isolationLevel=true Sets the isolation level of the transaction. * @param {string} options.isolationLevel=true Sets the isolation level of the transaction.
* @param {string} options.deferrable Sets the constraints to be deferred or immediately checked. * @param {string} options.deferrable Sets the constraints to be deferred or immediately checked.
...@@ -28,11 +27,9 @@ class Transaction { ...@@ -28,11 +27,9 @@ class Transaction {
this._afterCommitHooks = []; this._afterCommitHooks = [];
// get dialect specific transaction options // get dialect specific transaction options
const transactionOptions = sequelize.dialect.supports.transactionOptions || {};
const generateTransactionId = this.sequelize.dialect.QueryGenerator.generateTransactionId; const generateTransactionId = this.sequelize.dialect.QueryGenerator.generateTransactionId;
this.options = _.extend({ this.options = _.extend({
autocommit: transactionOptions.autocommit || null,
type: sequelize.options.transactionType, type: sequelize.options.transactionType,
isolationLevel: sequelize.options.isolationLevel, isolationLevel: sequelize.options.isolationLevel,
readOnly: false readOnly: false
...@@ -135,7 +132,6 @@ class Transaction { ...@@ -135,7 +132,6 @@ class Transaction {
return this.begin() return this.begin()
.then(() => this.setDeferrable()) .then(() => this.setDeferrable())
.then(() => this.setIsolationLevel()) .then(() => this.setIsolationLevel())
.then(() => this.setAutocommit())
.catch(setupErr => this.rollback().finally(() => { .catch(setupErr => this.rollback().finally(() => {
throw setupErr; throw setupErr;
})); }));
...@@ -164,13 +160,6 @@ class Transaction { ...@@ -164,13 +160,6 @@ class Transaction {
} }
} }
setAutocommit() {
return this
.sequelize
.getQueryInterface()
.setAutocommit(this, this.options.autocommit, this.options);
}
setIsolationLevel() { setIsolationLevel() {
return this return this
.sequelize .sequelize
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!