-
What's the best practice to decrement a field in one of my records? I took a look at #266 (from prisma1) but couldn't find it documented anywhere. I'm just trying to atomically decrement a field that I know exists, ideally in a single query. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Hey @jamesonev 👋 As a workaround, you would need to use await prisma.executeRaw(`update "Post" set views = views + 1 where id = 1`) |
Beta Was this translation helpful? Give feedback.
-
Hi @jamesonev , prisma.table.update({
where: { id: 1234 },
data: {views: {increment: 1}}
}); |
Beta Was this translation helpful? Give feedback.
-
I usually use:
|
Beta Was this translation helpful? Give feedback.
Hey @jamesonev 👋
Unfortunately this is not possible directly and there is an open issue for that as well here. Do add a 👍 on this so that we can measure the priority.
As a workaround, you would need to use
prisma.executeRaw
as follows. Here I am incrementing the Post's views.