egg-sequelize的事務(wù)操作
let transaction;
try {
// 建立事務(wù)對象
transaction = await this.ctx.model.transaction();
// 事務(wù)增操作
await this.ctx.model.VirtualDeptMember.create({
JSON格式數(shù)據(jù)
}, {
transaction,
});
// 事務(wù)刪操作
await this.ctx.model.VirtualDeptMember.destroy({
where: {
JSON格式數(shù)據(jù)
},
transaction,
});
// 事務(wù)改操作
await this.ctx.model.Device.update({
修改的JSON數(shù)據(jù)
}, {
where: {
查詢的JSON數(shù)據(jù)
},
transaction,
});
// 提交事務(wù)
await transaction.commit();
} catch (err) {
// 事務(wù)回滾
await transaction.rollback();
}