MCPcopy
hub / github.com/sequelize/sequelize / transaction

Method transaction

lib/sequelize.js:1095–1129  ·  lib/sequelize.js::Sequelize.transaction

* Start a transaction. When using transactions, you should pass the transaction in the options argument in order for the query to happen under that transaction @see {@link Transaction} * * If you have [CLS](https://github.com/Jeff-Lewis/cls-hooked) enabled, the transaction will automatically b

(options, autoCallback)

Source from the content-addressed store, hash-verified

1093 * @returns {Promise}
1094 */
1095 async transaction(options, autoCallback) {
1096 if (typeof options === class="st">'function') {
1097 autoCallback = options;
1098 options = undefined;
1099 }
1100
1101 const transaction = new Transaction(this, options);
1102
1103 if (!autoCallback) {
1104 await transaction.prepareEnvironment(false);
1105 return transaction;
1106 }
1107
1108 class="cm">// autoCallback provided
1109 return Sequelize._clsRun(async () => {
1110 try {
1111 await transaction.prepareEnvironment();
1112 const result = await autoCallback(transaction);
1113 await transaction.commit();
1114 return await result;
1115 } catch (err) {
1116 try {
1117 if (!transaction.finished) {
1118 await transaction.rollback();
1119 } else {
1120 class="cm">// release the connection, even if we don't need to rollback
1121 await transaction.cleanup();
1122 }
1123 } catch (err0) {
1124 class="cm">// ignore
1125 }
1126 throw err;
1127 }
1128 });
1129 }
1130
1131 /**
1132 * Use CLS (Continuation Local Storage) with Sequelize. With Continuation

Callers 15

testFunction · 0.80
upsert.tsFile · 0.80
connection.tsFile · 0.80
transFunction · 0.80
trans2Function · 0.80
trans3Function · 0.80
trans4Function · 0.80
transactFunction · 0.80
nestedTransactFunction · 0.80
excludeFromTransactionFunction · 0.80
User.tsFile · 0.80
findOrCreateMethod · 0.80

Calls 5

prepareEnvironmentMethod · 0.95
commitMethod · 0.95
rollbackMethod · 0.95
cleanupMethod · 0.95
_clsRunMethod · 0.80

Tested by 9

testFunction · 0.64
testAsyncFunction · 0.64
firstTransactionFunction · 0.64
secondTransactionFunction · 0.64
updateFunction · 0.64
verifyDeadlockFunction · 0.64
newTransactionFuncFunction · 0.64
describeDeferrableTestFunction · 0.64