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