1 minute read · database
Prisma makes database access type-safe and ergonomic. These patterns take it to the next level.
Transactions
const [post, _] = await prisma.$transaction([
prisma.post.create({ data: postData }),
prisma.user.update({ where: { id: authorId }, data: { postCount: { increment: 1 } } })
]);Cursor Pagination
const posts = await prisma.post.findMany({
take: 10, cursor: { id: lastId }, skip: 1, orderBy: { createdAt: 'desc' }
});Select Only What You Need
const user = await prisma.user.findUnique({ where: { id }, select: { id: true, name: true, email: true } });Conclusion
Use select, cursor pagination and transactions. These three habits prevent the most common Prisma performance problems.