medium10 pts · first answer countsprismatransactionssql
Moving credits between accounts
This code moves credits between two users. If the server crashes between the two lines, credits disappear. What is the right fix?
await prisma.account.update({
where: { id: fromId },
data: { credits: { decrement: amount } },
})
await prisma.account.update({
where: { id: toId },
data: { credits: { increment: amount } },
})Discussion 0
Join free to post in the discussion.
Related questions
- Preventing SQL injectionFull Stack Developer
- Listing users with zero ordersFull Stack Developer
- Comparing a column to NULLFull Stack Developer
- What an index costsFull Stack Developer
- Composite index column orderFull Stack Developer
- Write skew under snapshot isolationFull Stack Developer
- Two agents edit one ticketFull Stack Developer
- Items missing between pagesFull Stack Developer