8 lines
13 KiB
Plaintext
8 lines
13 KiB
Plaintext
|
{
|
||
|
"version": 3,
|
||
|
"sources": ["../src/transaction.js"],
|
||
|
"sourcesContent": ["'use strict';\n\n/**\n * The transaction object is used to identify a running transaction.\n * It is created by calling `Sequelize.transaction()`.\n * To run a query under a transaction, you should pass the transaction in the options object.\n *\n * @class Transaction\n * @see {@link Sequelize.transaction}\n */\nclass Transaction {\n /**\n * Creates a new transaction instance\n *\n * @param {Sequelize} sequelize A configured sequelize Instance\n * @param {object} options An object with options\n * @param {string} [options.type] Sets the type of the transaction. Sqlite only\n * @param {string} [options.isolationLevel] Sets the isolation level of the transaction.\n * @param {string} [options.deferrable] Sets the constraints to be deferred or immediately checked. PostgreSQL only\n * @param {boolean} [options.readOnly] Whether this transaction will only be used to read data. Used to determine whether sequelize is allowed to use a read replication server.\n */\n constructor(sequelize, options) {\n this.sequelize = sequelize;\n this.savepoints = [];\n this._afterCommitHooks = [];\n\n // get dialect specific transaction options\n const generateTransactionId = this.sequelize.dialect.queryGenerator.generateTransactionId;\n\n this.options = {\n type: sequelize.options.transactionType,\n isolationLevel: sequelize.options.isolationLevel,\n readOnly: false,\n ...options\n };\n\n this.parent = this.options.transaction;\n\n if (this.parent) {\n this.id = this.parent.id;\n this.parent.savepoints.push(this);\n this.name = `${this.id}-sp-${this.parent.savepoints.length}`;\n } else {\n this.id = this.name = generateTransactionId();\n }\n\n delete this.options.transaction;\n }\n\n /**\n * Commit the transaction\n *\n * @returns {Promise}\n */\n async commit() {\n if (this.finished) {\n throw new Error(`Transaction cannot be committed because it has been finished with state: ${this.finished}`);\n }\n\n try {\n await this.sequelize.getQueryInterface().commitTransaction(this, this.options);\n this.cleanup();\n } catch (e) {\n console.warn(`Committing transaction ${this.id} failed with error ${JSON.stringify(e.message)}. We are killing its connection as it is now in an undetermined state.`);\n await this.forceCleanup();\n\n throw e;\n } finally {\n this.finished = 'commit';\n for (const hook of this._afterCommitHooks) {\n await hook.apply(this, [this]);\n }\n }\n }\n\n /**\n * Rollback (abort) the transaction\n *\n * @returns {Promise}\n */\n async rollback() {\n if (this.finished) {\n throw new Error(`Transaction cannot be rolled back because it has been finished with state: ${this.finished}`);\n }\n\n if (!this.connection) {\n throw new Error('Transaction cannot be rolled back because it never started');\n }\n\n try {\n await this\n .sequelize\n .getQueryInterface()\n .rollbackTransaction(this, this.options);\n\n this.cleanup();\n } catch (e) {\n console.warn(`Rolling back transaction ${this.id} failed with error ${JSON.stringify(e.message)}. We are killing its connection as it is now in an undetermined state.`);\n await this.forceCleanup();\n\n throw e;\n }\n }\n\n /**\n * Called to acquire a connection to use and set the correct options on the connection.\n * We should ensure all of the environment that's set up is cleaned up in `cleanup()` below.\n *\n * @param {boolean} useCLS Defaults to true: Use CLS (Continuation Local Storage) with Sequelize. With CLS, all queries within the transaction callback will automatically receive the transaction object.\n * @returns {Promise}\n */\n async prepareEnvironment(useCLS = true) {\n let connectionPromise;\n\n if (this.parent) {\n connectionPromise = Promise.resolve(this.parent.connection);\n } else {\n const acquireOptions = { uuid: this.id };\n if (this.options.readOnly) {\n
|
||
|
"mappings": ";;;;;;;;;;;;;;;;;AAUA,kBAAkB;AAAA,EAWhB,YAAY,WAAW,SAAS;AAC9B,SAAK,YAAY;AACjB,SAAK,aAAa;AAClB,SAAK,oBAAoB;AAGzB,UAAM,wBAAwB,KAAK,UAAU,QAAQ,eAAe;AAEpE,SAAK,UAAU;AAAA,MACb,MAAM,UAAU,QAAQ;AAAA,MACxB,gBAAgB,UAAU,QAAQ;AAAA,MAClC,UAAU;AAAA,OACP;AAGL,SAAK,SAAS,KAAK,QAAQ;AAE3B,QAAI,KAAK,QAAQ;AACf,WAAK,KAAK,KAAK,OAAO;AACtB,WAAK,OAAO,WAAW,KAAK;AAC5B,WAAK,OAAO,GAAG,KAAK,SAAS,KAAK,OAAO,WAAW;AAAA,WAC/C;AACL,WAAK,KAAK,KAAK,OAAO;AAAA;AAGxB,WAAO,KAAK,QAAQ;AAAA;AAAA,QAQhB,SA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