prisma transaction 1

prisma transaction

const [posts, totalPosts] = await prisma.$transaction([
  prisma.post.findMany({ where: { title: { contains: 'prisma' } } }),  
  prisma.post.count(),
])

Here is what the above code is Doing:
1. It starts a transaction
2. It executes the first query, which returns a list of posts
3. It executes the second query, which returns the total number of posts
4. It commits the transaction
5. It returns the results of the two queries

Similar Posts