Performance: Why Prisma offers type-safe database access
This concept affects development speed and runtime error reduction, indirectly improving user experience by preventing runtime crashes and unnecessary database queries.
const user = await prisma.user.findUnique({ where: { id: userId } });const user = await prisma.$queryRaw`SELECT * FROM users WHERE id = ${userId}`;
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Raw SQL queries without type safety | N/A | N/A | N/A | [X] Bad |
| Prisma type-safe queries | N/A | N/A | N/A | [OK] Good |
const user = await prisma.user.findUnique({ where: { id: 5 } });id field does not exist in the database schema?id is missing, TypeScript will catch this mismatch during compilation, preventing runtime errors.const posts = await prisma.post.findMany({ where: { title: 'Hello' } });Property 'title' does not exist on type 'PostWhereInput'.title is not a valid filter field, meaning it is not defined in the Prisma schema for Post.findMany is valid here.title field is missing in the Prisma schema for Post -> Option Aprisma generate updates the generated client with types matching the current schema.prisma generate after updating the Prisma schema file -> Option APass the test and this pattern moves unknown