Row locking on prisma suggestions
Hi, I have been using Prisma to develop a text based game, this has been going very smooth. However I have been stumbling on some very big issues for concurrent updates on certain rows e.g. auction, withdraw, depositing, where my players can get under their balance if they click very fast, which results in a - balance and offcourse unwanted results.
I was able to solve this with raw sql row locking, see picture. However I think the way to do this isn't very smooth and I have to change some extra things on plus to get the collect errors in the frontend.
I am contemplating switching from ORM, but I was wondering if there are some better ways to solve these race conditions.
I have tried optimistic locking a few weeks ago but had some issues there. I want to have a good decoupled code without having to many changes in response/logic for specific locking cases.
Any tips here how I should proceed further?
1 Reply
Hello @Jeroen_v_g 👋
Have you considered using the new TypedSQL feature?
https://www.prisma.io/typedsql
I was going to suggest optimistic locking. However as you mentioned that you have already tried it, can you let us know what issues you ran into?
Prisma
TypedSQL: Fully type-safe raw SQL in Prisma ORM
Write raw sql queries with fully type-safety and auto-completion in Prisma ORM. Get type-safe database queries without sacrificing the power and flexibility of raw SQL.