nested transactions
Hey, i got something like -> prisma.transaction(async prisma => {
test(1)
test(2)
})
test1(() => {
and here i got another prisma.transcation(async prisma => {
prisma stuff to do
})
test2(() => {
and here i got another prisma.transcation(async prisma => {
prisma stuff to do
})
})
if i throw an error in test1() everything is fine and both transactions are not done.
if i throw an error in test2(), my first transaction gets commited.
if i swap test1() and test2() and i throw the error still in test2() all works fine.
My Problem is - how can i rely on that? if the functions must be in the right order, so my transaction is rolled back i got no way to make this save. How to handle this`? i really dont want to try and catch and rollback all myself because then i need no transaction.
Any suggestions?
3 Replies
Prisma.transaction
needs to be provided with an array of Prisma promises. Depending on how much extra stuff is being done inside test1() and test2(), can you use the Prisma calls inside those functions directly? eg.
@Rarityyeah i guess i have to rearrange my code - i dont like that tbh because i need to call this functions on its own on a functions but i guess i can only go like that - ty
@moosthuizen it worked with my syntax prisma.transcation(async ptrans => {}) but i need to give the ptrans into every single function and use it there and not my prisma client, its disgusting but working
haha, sounds elegant in its own way