是否可以像这样还原已提交的事务:
const trx = await transaction.start(Model.knex());
try {
await doStuff(trx);
await doOtherStuff(trx); // If this fails rollback is working well
await trx.commit();
await externalAPICall(); // External API call failed! Error!
} catch (err) {
await trx.rollback(err); // Can I rollback if externalAPICall throwed and error? (Commit is already done)
}
我会这样做:
await knex.transaction(async (trx) => {
await doStuff(trx);
await doOtherStuff(trx);
await externalAPICall();
}
在此语法中,commit(( 和 rollback(( 是隐式:)