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

Commit d1bbf25a by Eric Thompson

Added Transaction Type

1 parent e3eb5236
......@@ -365,7 +365,7 @@ var QueryGenerator = {
return 'SAVEPOINT ' + this.quoteIdentifier(transaction.name) + ';';
}
return 'BEGIN TRANSACTION;';
return 'BEGIN ' + transaction.options.type + ' TRANSACTION;';
},
setAutocommitQuery: function() {
......
......@@ -79,6 +79,7 @@ var url = require('url')
* @param {Integer} [options.pool.maxIdleTime] The maximum time, in milliseconds, that a connection can be idle before being released
* @param {Function} [options.pool.validateConnection] A function that validates a connection. Called with client. The default function checks that client is an object, and that its state is not disconnected
* @param {Boolean} [options.quoteIdentifiers=true] Set to `false` to make table names and attributes case-insensitive on Postgres and skip double quoting of them.
* @param {String} [options.transactionType='DEFERRED'] Set the default transaction type. See `Sequelize.Transaction.TYPES` for possible options.
* @param {String} [options.isolationLevel='REPEATABLE_READ'] Set the default transaction isolation level. See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options.
* @param {Boolean} [options.typeValidation=false] Run built in type validators on insert and update, e.g. validate that arguments passed to integer fields are integer-like
*/
......@@ -143,6 +144,7 @@ var Sequelize = function(database, username, password, options) {
pool: {},
quoteIdentifiers: true,
hooks: {},
transactionType: Transaction.TYPES.DEFERRED,
isolationLevel: Transaction.ISOLATION_LEVELS.REPEATABLE_READ,
databaseVersion: 0,
typeValidation: false
......@@ -285,7 +287,7 @@ Object.defineProperty(Sequelize.prototype, 'connectorManager', {
});
/**
* A reference to the sequelize transaction class. Use this to access isolationLevels when creating a transaction
* A reference to the sequelize transaction class. Use this to access isolationLevels and types when creating a transaction
* @property Transaction
* @see {Transaction}
* @see {Sequelize#transaction}
......@@ -1200,6 +1202,7 @@ Sequelize.where = Sequelize.condition = Sequelize.prototype.condition = Sequeliz
* @param {Object} [options={}]
* @param {Boolean} [options.autocommit=true]
* @param {String} [options.type='DEFERRED'] See `Sequelize.Transaction.TYPES` for possible options
* @param {String} [options.isolationLevel='REPEATABLE_READ'] 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.
* @return {Promise}
......
......@@ -13,6 +13,7 @@ var Utils = require('./utils')
* @param {Sequelize} sequelize A configured sequelize Instance
* @param {Object} options An object with options
* @param {Boolean} options.autocommit=true 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.
*/
......@@ -21,6 +22,7 @@ var Transaction = module.exports = function(sequelize, options) {
this.savepoints = [];
this.options = Utils._.extend({
autocommit: true,
type: sequelize.options.transactionType,
isolationLevel: sequelize.options.isolationLevel
}, options || {});
......@@ -39,6 +41,45 @@ var Transaction = module.exports = function(sequelize, options) {
};
/**
* Types can be set per-transaction by passing `options.type` to `sequelize.transaction`.
* Default to `DEFERRED` but you can override the default type by passing `options.transactionType` in `new Sequelize`.
*
* The possible types to use when starting a transaction:
*
* ```js
* {
* DEFERRED: "DEFERRED",
* IMMEDIATE: "IMMEDIATE",
* EXCLUSIVE: "EXCLUSIVE"
* }
* ```
*
* Pass in the desired level as the first argument:
*
* ```js
* return sequelize.transaction({
* type: Sequelize.Transaction.EXCLUSIVE
* }, function (t) {
*
* // your transactions
*
* }).then(function(result) {
* // transaction has been committed. Do something after the commit if required.
* }).catch(function(err) {
* // do something with the err.
* });
* ```
*
* @property TYPES
*/
Transaction.TYPES = {
DEFERRED: "DEFERRED",
IMMEDIATE: "IMMEDIATE",
EXCLUSIVE: "EXCLUSIVE"
};
/**
* Isolations levels can be set per-transaction by passing `options.isolationLevel` to `sequelize.transaction`.
* Default to `REPEATABLE_READ` but you can override the default isolation level by passing `options.isolationLevel` in `new Sequelize`.
*
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!