legiahoang
10/21/2017 - 10:23 AM

sequelize transaction await

try {
  // get transaction
  const transaction = await sequelize.transaction();

  // step 1
  await Model.destroy({where: {id}}, {transaction});

  // step 2
  await Model.create({}, {transaction});

  // commit
  await transaction.commit();

} catch (err) {
  // Rollback transaction if any errors were encountered
  await transaction.rollback();
}

https://stackoverflow.com/questions/42870374/node-js-7-how-to-use-sequelize-transaction-with-async-await/43342688#43342688