Skip to content

Commit

Permalink
refactor(transaction): remove autocommit mode (#9921)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsasaki609 authored and sushantdhiman committed Sep 19, 2018
1 parent 98afe2e commit ee9ec57
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 86 deletions.
1 change: 0 additions & 1 deletion docs/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ The following options (with their default values) are available:

```js
{
autocommit: true,
isolationLevel: 'REPEATABLE_READ',
deferrable: 'NOT DEFERRABLE' // implicit default of postgres
}
Expand Down
21 changes: 0 additions & 21 deletions lib/dialects/abstract/query-generator/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,6 @@
const uuidv4 = require('uuid/v4');

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.
*
Expand Down
4 changes: 0 additions & 4 deletions lib/dialects/mssql/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,10 +795,6 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator {
});
}

setAutocommitQuery() {
return '';
}

setIsolationLevelQuery() {

}
Expand Down
19 changes: 0 additions & 19 deletions lib/dialects/postgres/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,25 +906,6 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
dropForeignKeyQuery(tableName, 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;
3 changes: 1 addition & 2 deletions lib/dialects/sqlite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype
where: true
},
transactionOptions: {
type: true,
autocommit: false
type: true
},
constraints: {
addConstraint: false,
Expand Down
5 changes: 0 additions & 5 deletions lib/dialects/sqlite/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,6 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator {
return 'BEGIN ' + transaction.options.type + ' TRANSACTION;';
}

setAutocommitQuery() {
// SQLite does not support SET autocommit
return null;
}

setIsolationLevelQuery(value) {
switch (value) {
case Transaction.ISOLATION_LEVELS.REPEATABLE_READ:
Expand Down
22 changes: 0 additions & 22 deletions lib/query-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -1297,28 +1297,6 @@ class QueryInterface {
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) {
if (!transaction || !(transaction instanceof Transaction)) {
throw new Error('Unable to set isolation level for a transaction without transaction object!');
Expand Down
1 change: 0 additions & 1 deletion lib/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,6 @@ class Sequelize {
* // Note, that CLS is enabled for all sequelize instances, and all instances will share the same namespace
*
* @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.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.
Expand Down
11 changes: 0 additions & 11 deletions lib/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Transaction {
*
* @param {Sequelize} sequelize A configured sequelize Instance
* @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.isolationLevel=true Sets the isolation level of the transaction.
* @param {string} options.deferrable Sets the constraints to be deferred or immediately checked.
Expand All @@ -28,11 +27,9 @@ class Transaction {
this._afterCommitHooks = [];

// get dialect specific transaction options
const transactionOptions = sequelize.dialect.supports.transactionOptions || {};
const generateTransactionId = this.sequelize.dialect.QueryGenerator.generateTransactionId;

this.options = _.extend({
autocommit: transactionOptions.autocommit || null,
type: sequelize.options.transactionType,
isolationLevel: sequelize.options.isolationLevel,
readOnly: false
Expand Down Expand Up @@ -135,7 +132,6 @@ class Transaction {
return this.begin()
.then(() => this.setDeferrable())
.then(() => this.setIsolationLevel())
.then(() => this.setAutocommit())
.catch(setupErr => this.rollback().finally(() => {
throw setupErr;
}));
Expand Down Expand Up @@ -164,13 +160,6 @@ class Transaction {
}
}

setAutocommit() {
return this
.sequelize
.getQueryInterface()
.setAutocommit(this, this.options.autocommit, this.options);
}

setIsolationLevel() {
return this
.sequelize
Expand Down

0 comments on commit ee9ec57

Please sign in to comment.