custom prisma transaction rollbacks for handled errors #398
Replies: 3 comments 1 reply
-
|
Hi, your reasoning seems correct. The result unwrapping must be done in the adapter in order for the rollback to work. With the addition of support for nested transactions, the adapter is a bit more complicated now, EDIT: I mixed it up with the Drizzle ORM adapter, there's no Let me know if you have any trouble with the implementation. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the info @Papooch . Where exactly is the |
Beta Was this translation helpful? Give feedback.
-
|
Right okay. I will likely need savepoints. Most backend workflows I have will likely use the Slight tangent. It's tricky with the Result monad. There are handled errors where you want to rollback everything (e.g. a db failure), and there's other handled errors where that you may want to trigger additional actions (e.g. db returns null unexpectedly, card payment declines...). It's possible I'm actually overusing the Result monad perhaps. Anyways - do you ever find with the transactional decorator that there are some edgier cases where it's hard to get the rollback behaviour just right? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
@Papooch, I was hoping for some advice on implementing a custom rollback method when errors are handled rather than thrown. I've added the relevant code below.
I'm using a Result type that wraps all prisma methods:
Example method call:
I'm thinking of extending the TransactionalAdapterPrisma class like so:
My understanding is that this will roll back the transaction both if:
fnthrows an error; and if,fnreturnsTErrCouple questions on the above:
p.$executeRawROLLBACK;` work for manually rolling back transactions? I've seen that prisma doesnt yet have an ORM method for rolling back transactions, but I saw my proposed solution was recommended here.Apologies if these are basic questions, I'm new to managing prisma transactions directly. I previously had a more manual rollback system which was flawed as you rightfully point out to me last year! This solution is based on this issue I saw although hopefully this discussion encapsulates the solution a bit more completely.
Thanks in advance 🙏
Beta Was this translation helpful? Give feedback.
All reactions