美文网首页
Node.js how to use sequelize tr

Node.js how to use sequelize tr

作者: 梁同桌 | 来源:发表于2018-05-29 14:48 被阅读132次
    let transaction;    
    
    try {
      // get transaction
      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

    相关文章

      网友评论

          本文标题:Node.js how to use sequelize tr

          本文链接:https://www.haomeiwen.com/subject/nlcajftx.html