[bug] transaction callback function do not accept arguments
bingtsingw opened this issue · 4 comments
bingtsingw commented
As in the doc
await db.$transaction(async (db) => {
//
});
Transaction callback function should accept a db
argument, but it does not have, so I can't use repo in the transaction callback
romeerez commented
Well, it's not a bug, but an old doc, so the transaction doesn't pass the db
argument and it's intended to be so.
bingtsingw commented
How about using repo in transactions, is it necessary
await db.$transaction(async (db) => {
// wrong: userRepo is using a main `db` by default
await userRepo.search(query);
// need to provide `db.user` explicitly:
await userRepo(db.user).search(query);
});
romeerez commented
No, no longer necessary. It's an old doc when it was important to pass the db
instance to ensure that queries perform in the same transaction. But later the logic was changed so that it will execute on the existing transaction implicitly.
Thanks for pointing to these docs, need to update them.
await db.$transaction(async () => {
// it's ok, no problems
await userRepo.search(query);
});
romeerez commented
Updated the doc