我正在进行两个存储库调用来更新db中两个不同表的数据。我想实现一个事务。需要帮助如何执行这个。https:/loopback.iodocenlb4Using-database-transactions.html。从文档上看,交易只能在一个仓库中执行,而不能在两个仓库之间执行。
const created = await repo.create({title: 'Groceries'}, {transaction: tx});
const updated = await repo.update(
{title: 'Errands', id: created.id},
{transaction: tx},
);
// commit the transaction to persist the changes
await tx.commit();
但我想
const created = await repo1.create({title: 'Groceries'}, {transaction: tx});
const updated = await repo2.update(
{title: 'Errands', id: created.id},
{transaction: tx},
);
// commit the transaction to persist the changes
await tx.commit();
有谁知道如何做到这一点。
const created = await repo1.create({title: 'Groceries'}, {transaction: tx}); const updated = await repo2.update( {title: 'Errands', id: created.id},{transaction: tx}, ); // commit the transaction to persist the changes await tx.commit();
是的,如果你的repo1和repo2属于同一个数据源,这是可能的。
更多信息 此处