📜  如何使用 sequelize 执行交易 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:36.027000             🧑  作者: Mango

代码示例1
return sequelize.transaction().then(function (t) {
  return User.create({
    firstName: 'Homer',
    lastName: 'Simpson'
  }, {transaction: t}).then(function (user) {
    return user.addSibling({
      firstName: 'Lisa',
      lastName: 'Simpson'
    }, {transaction: t});
  }).then(function () {
    return t.commit();
  }).catch(function (err) {
    return t.rollback();
  });
});