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

Method transaction

src/sequelize.js:1178–1211  ·  view source on GitHub ↗

* 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 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

1176 * @returns {Promise}
1177 */
1178 async transaction(options, autoCallback) {
1179 if (typeof options === 'function') {
1180 autoCallback = options;
1181 options = undefined;
1182 }
1183
1184 const transaction = new Transaction(this, options);
1185
1186 if (!autoCallback) {
1187 await transaction.prepareEnvironment(/* cls */ false);
1188 return transaction;
1189 }
1190
1191 // autoCallback provided
1192 return Sequelize._clsRun(async () => {
1193 await transaction.prepareEnvironment(/* cls */ true);
1194
1195 let result;
1196 try {
1197 result = await autoCallback(transaction);
1198 } catch (err) {
1199 try {
1200 await transaction.rollback();
1201 } catch (ignore) {
1202 // ignore, because 'rollback' will already print the error before killing the connection
1203 }
1204
1205 throw err;
1206 }
1207
1208 await transaction.commit();
1209 return result;
1210 });
1211 }
1212
1213 /**
1214 * Use CLS (Continuation Local Storage) with Sequelize. With Continuation

Callers 15

cls.test.jsFile · 0.80
testHooksFunction · 0.80
model.test.jsFile · 0.80
testAsyncFunction · 0.80
firstTransactionFunction · 0.80
secondTransactionFunction · 0.80
updateFunction · 0.80
verifyDeadlockFunction · 0.80
newTransactionFuncFunction · 0.80
sequelize.test.jsFile · 0.80

Calls 4

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

Tested by 10

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