Prisma increase count by 1 after Find query

I am trying to count how many times a record was viewed by users by managing a field called views in the table. I want to increase the count every time a record is pulled to be sent by the API.

What's the right and fastest way to do it while not blocking the thread to return the data to the frontend.

Stack: NextJS and Prisma

1 Answer

You can use atomic number operations in this case.

await prisma.model.update({ where: { id: 'some-id' }, data: { value: { increment: 1 } } }) 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like