Performance: Prisma Client usage
This affects server response time and database query efficiency, impacting how fast data is fetched and sent to the frontend.
const users = await prisma.user.findMany({ include: { posts: true } });const users = await prisma.user.findMany(); for (const user of users) { user.posts = await prisma.post.findMany({ where: { authorId: user.id } }); }
| Pattern | Database Queries | Server Response Time | Network Payload | Verdict |
|---|---|---|---|---|
| N+1 Query Pattern | Multiple queries (N+1) | High due to many DB calls | Larger due to repeated data | [X] Bad |
| Single Query with Include | Single optimized query | Low and consistent | Smaller and efficient | [OK] Good |
const user = await prisma.user.findUnique({ where: { id: 5 } });
console.log(user);import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function getUsers() {
const users = prisma.user.findMany();
return users;
}Pass the test and this pattern moves unknown