Transactions across Files
I have the following two calls, one a direct Prisma call and the other one a Service call which does multiple inner Prisma calls.
I found this discussion related to it: https://github.com/prisma/prisma/issues/12975 Is there no way to implement this as a transaction? At least it would be useful to provide a workaround as an example like mentioned over here: https://github.com/prisma/prisma/issues/12975#issuecomment-1426915067
So my guess is that we should use interactive transactions and pass the tx to the service, correct?
https://www.prisma.io/docs/orm/prisma-client/queries/transactions#example
GitHub
Does Prisma offer Transactions across multiple files? ยท Issue #1297...
Discussed in #12974 Originally posted by jaequery April 23, 2022 Coming from TypeORM, I am surprised to see that Prisma does not have any way to perform transactions in a similar way TypeORM does. ...
Transactions and batch queries (Reference) | Prisma Documentation
This page explains the transactions API of Prisma Client.
3 Replies
Hello @rwieruch ๐
So my guess is that we should use interactive transactions and pass the tx to the service, correct?Yes, you are correct! Have you seen this example of using Callback free Interactive Transaction with Prisma Client Extensions: https://github.com/prisma/prisma-client-extensions/tree/main/callback-free-itx You can also consider taking inspiration from the above example
GitHub
prisma-client-extensions/callback-free-itx at main ยท prisma/prisma-...
Examples of Prisma Client extensions. Contribute to prisma/prisma-client-extensions development by creating an account on GitHub.
Callback free, meaining that we do not need to use an itneractive transaction, correct? But I would still need to pass the
tx
to my service layers.
The implementation looks interesting, but personally I wouldn't want to maintain this myself. So I would stay with the interactive transaction I guess.You are correct that you will need to pass
tx
to your service layers.
I would stay with the interactive transaction I guess.This sounds good! ๐