1. 程式人生 > >nodejs sql --- 新增事務

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