添加事务
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