Skip to content

Best way to increment/decrement a field? #3176

Answered by ryands17
jamesonev asked this question in Q&A
Discussion options

You must be logged in to vote

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.

await prisma.executeRaw(`update "Post" set views = views + 1 where id = 1`)

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
1 reply
@moishinetzer
Comment options

Answer selected by jamesonev
Comment options

You must be logged in to vote
4 replies
@bluuewhale
Comment options

@mualle
Comment options

@camilo86
Comment options

@opaque-maniac
Comment options

Comment options

You must be logged in to vote
2 replies
@ujjwal-kr
Comment options

@janpio
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet