MCPcopy
hub / github.com/sequelize/sequelize / update

Function update

test/integration/transaction.test.js:443–476  ·  test/integration/transaction.test.js::update
(sequelize, Task, from, to)

Source from the content-addressed store, hash-verified

441 class="cm">// Lock the row with id of `from`, and then try to update the row
442 class="cm">// with id of `to`
443 const update = async (sequelize, Task, from, to) => {
444 await sequelize
445 .transaction(async transaction => {
446 try {
447 try {
448 await Task.findAll({
449 where: { id: { [Sequelize.Op.eq]: from } },
450 lock: transaction.LOCK.UPDATE,
451 transaction
452 });
453
454 await delay(10);
455
456 await Task.update(
457 { id: to },
458 {
459 where: { id: { [Sequelize.Op.ne]: to } },
460 lock: transaction.LOCK.UPDATE,
461 transaction
462 }
463 );
464 } catch (e) {
465 console.log(e.message);
466 }
467
468 await Task.create({ id: 2 }, { transaction });
469 } catch (e) {
470 console.log(e.message);
471 }
472
473 throw new Error(class="st">'Rollback!');
474 })
475 .catch(() => {});
476 };
477
478 it(class="st">'should treat deadlocked transaction as rollback', async function() {
479 const Task = await getAndInitializeTaskModel(this.sequelize);

Callers 1

Calls 5

transactionMethod · 0.80
findAllMethod · 0.80
logMethod · 0.80
updateMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected