Prisma: avoid N+1 with include/select

6070
0

Prisma makes it easy to write readable queries, but you can still create N+1 patterns by fetching parents and then fetching children in a loop. I prefer using include or select to get related data in one query when the cardinality is reasonable. I also select only the fields I actually need—smaller payloads and less serialization overhead. When I need more control, I’ll drop to raw SQL for hot paths. The broader lesson is to profile, not guess. Once you identify an N+1, the fix is often simple, especially if data access is centralized and query patterns are consistent.