From 4ccb2ec15625ff864208aa5c1bb2d087a9fcc9cb Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Mon, 22 Feb 2016 11:52:35 -0800 Subject: [PATCH 1/3] Added Transaction Type access --- sequelize/sequelize.d.ts | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index cbfc3db18..292649c0d 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -5176,6 +5176,14 @@ declare module "sequelize" { */ isolationLevel? : string; + /** + * Set the default transaction type. See `Sequelize.Transaction.TRANSACTION_TYPES` for possible + * options. + * + * Defaults to 'DEFERRED' + */ + transactionType? : string; + } /** @@ -5786,6 +5794,41 @@ declare module "sequelize" { */ ISOLATION_LEVELS : TransactionIsolationLevels; + /** + * Transaction type can be set per-transaction by passing `options.type` to + * `sequelize.transaction`. Default to `DEFERRED` but you can override the default isolation level + * by passing `options.transactionType` in `new Sequelize`. + * + * The transaction types to use when starting a transaction: + * + * ```js + * { + * DEFERRED: "DEFERRED", + * IMMEDIATE: "IMMEDIATE", + * EXCLUSIVE: "EXCLUSIVE" + * } + * ``` + * + * Pass in the transaction type 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. + * }); + * ``` + * + * @see TRANSACTION_TYPES + */ + TRANSACTION_TYPES : TransactionTypes; + /** * Possible options for row locking. Used in conjuction with `find` calls: * @@ -5837,6 +5880,17 @@ declare module "sequelize" { SERIALIZABLE: string; // 'SERIALIZABLE' } + /** + * Transaction type can be set per-transaction by passing `options.type` to `sequelize.transaction`. + * Default to `DEFERRED` but you can override the default isolation level by passing + * `options.transactionType` in `new Sequelize`. + */ + interface TransactionTypes { + DEFERRED: string; // 'DEFERRED' + IMMEDIATE: string; // 'IMMEDIATE' + EXCLUSIVE: string; // 'EXCLUSIVE' + } + /** * Possible options for row locking. Used in conjuction with `find` calls: */ @@ -5861,6 +5915,11 @@ declare module "sequelize" { */ isolationLevel?: string; + /** + * See `Sequelize.Transaction.TRANSACTION_TYPES` for possible options + */ + type?: string; + /** * A function that gets executed while running the query to log the sql. */ From f5f328d3b2c57254f3e345929bd9e2be2eed0510 Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Tue, 23 Feb 2016 09:31:11 -0800 Subject: [PATCH 2/3] Added tests for transaction types --- sequelize/sequelize-tests.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sequelize/sequelize-tests.ts b/sequelize/sequelize-tests.ts index b7a04761f..99b51a3df 100644 --- a/sequelize/sequelize-tests.ts +++ b/sequelize/sequelize-tests.ts @@ -1567,3 +1567,13 @@ s.transaction( function() { s.transaction( { isolationLevel : 'SERIALIZABLE' }, function( t ) { return Promise.resolve(); } ); s.transaction( { isolationLevel : s.Transaction.ISOLATION_LEVELS.SERIALIZABLE }, (t) => Promise.resolve() ); s.transaction( { isolationLevel : s.Transaction.ISOLATION_LEVELS.READ_COMMITTED }, (t) => Promise.resolve() ); + +// transaction types +new Sequelize( '', { transactionType: 'DEFERRED' } ); +new Sequelize( '', { transactionType: Sequelize.Transaction.TYPES.DEFERRED} ); +new Sequelize( '', { transactionType: Sequelize.Transaction.TYPES.IMMEDIATE} ); +new Sequelize( '', { transactionType: Sequelize.Transaction.TYPES.EXCLUSIVE} ); +s.transaction( { type : 'DEFERRED' }, (t) => Promise.resolve() ); +s.transaction( { type : s.Transaction.TYPES.DEFERRED }, (t) => Promise.resolve() ); +s.transaction( { type : s.Transaction.TYPES.IMMEDIATE }, (t) => Promise.resolve() ); +s.transaction( { type : s.Transaction.TYPES.EXCLUSIVE }, (t) => Promise.resolve() ); From 6f2803aff1d0f9bd32c9c14eb7ee041c516976a0 Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Tue, 23 Feb 2016 09:36:54 -0800 Subject: [PATCH 3/3] Corrected type name --- sequelize/sequelize.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index 292649c0d..11a07f4de 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -5177,7 +5177,7 @@ declare module "sequelize" { isolationLevel? : string; /** - * Set the default transaction type. See `Sequelize.Transaction.TRANSACTION_TYPES` for possible + * Set the default transaction type. See `Sequelize.Transaction.TYPES` for possible * options. * * Defaults to 'DEFERRED' @@ -5825,9 +5825,9 @@ declare module "sequelize" { * }); * ``` * - * @see TRANSACTION_TYPES + * @see Sequelize.Transaction.TYPES */ - TRANSACTION_TYPES : TransactionTypes; + TYPES : TransactionTypes; /** * Possible options for row locking. Used in conjuction with `find` calls: @@ -5916,7 +5916,7 @@ declare module "sequelize" { isolationLevel?: string; /** - * See `Sequelize.Transaction.TRANSACTION_TYPES` for possible options + * See `Sequelize.Transaction.TYPES` for possible options */ type?: string;