nodejs  sql --- 添加事务

 

添加事务

        let transaction; 

        try {
            transaction = await this.ctx.model.transaction();

            await this.ctx.model.Collect.create({id: 39, author: 'zyu111', count: 1}, {transaction})

            await this.ctx.model.Collect.create({id: 42, author: 'zyu8228', count: 1}, {transaction})

            await transaction.commit();

        } catch (err) {
            // console.log(err)
            console.log('回滚了。。。')
            await transaction.rollback();
        }

 

事务的操作对象 必须是 model 

相关文章:

  • 2022-12-23
  • 2021-07-18
  • 2022-12-23
  • 2021-06-06
  • 2022-02-05
  • 2021-07-21
  • 2022-12-23
猜你喜欢
  • 2021-09-18
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案