ecc-prisma-patterns

Guides Prisma schema design, queries, transactions, migrations, and serverless connection pooling in TypeScript backends.

Updated Apr 18, 2025
One-click install
npx skills add https://github.com/adriancodes/dotfiles --skill ecc-prisma-patterns-adriancodes
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ecc-prisma-patterns
Source: https://github.com/adriancodes/dotfiles/tree/main/dot_agents/skills/ecc-prisma-patterns
Command: npx skills add https://github.com/adriancodes/dotfiles --skill ecc-prisma-patterns-adriancodes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Prisma developers frequently hit subtle production traps: N+1 query loops, interactive transactions timing out after 5 seconds, updateMany returning counts instead of records, migrate dev resetting databases, and connection pool exhaustion in serverless deployments. This Skill provides version-aware patterns and anti-patterns to avoid these failures. ## Core Features & Use Cases - Schema and Query Patterns: ID strategy selection, index justification, include vs select trade-offs, cursor pagination with stable secondary ordering, and soft-delete filtering. - Transaction and Error Handling: Array vs interactive transaction selection, PrismaClient singleton setup with adapter or direct initialization, and mapping P2002/P2025/P2003 errors to domain exceptions. - Migration and Serverless Safety: Guidance on migrate dev vs migrate deploy, expand-and-contract migration planning, and connection pool sizing for Vercel, Lambda, and PgBouncer environments. - Use Case: When debugging a "Transaction already closed" error in a Next.js API route, use this Skill to identify that an external email call inside an interactive transaction exceeded the 5-second default timeout and restructure the code to move external calls outside the transaction. ## Quick Start Review my Prisma schema and query code for performance traps, transaction misuse, and serverless connection pool issues.

Frequently Asked Questions about ecc-prisma-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix N+1 query problems in Prisma?▼

Replace per-row relation queries inside loops with a single findMany using include or select to load relations. Verify the actual relation load strategy in your installed version, since JOIN behavior depends on the Prisma version, provider, and enabled features.

How do I configure Prisma connection pooling for serverless?▼

For legacy engine pools, set connection_limit and pool_timeout as URL parameters in DATABASE_URL. Adapter-based setups use native driver options like max on the PostgreSQL pool. Size aggregate connections across all function instances to avoid exhausting the database.

Why does my Prisma interactive transaction fail after 5 seconds?▼

Interactive transactions time out after 5 seconds by default, and external calls like sending email inside the transaction exceed this limit. Move external calls outside the transaction, or raise the timeout option only when bulk processing genuinely requires it.

Does Prisma updateMany return the updated records?▼

No, updateMany returns only a count object like { count: 2 }, not the updated rows. Newer Prisma versions offer updateManyAndReturn where supported by the provider; otherwise plan a transaction with defined isolation semantics.

Can Prisma migrate dev delete my database data?▼

Yes, migrate dev detects schema drift and may prompt to reset the database, dropping all data. Use migrate dev only on isolated development databases and migrate deploy in CI/CD, with backups and rollback planning for production targets.

Why does findUniqueOrThrow return soft-deleted records?▼

findUniqueOrThrow throws P2025 only when the row does not exist in the database; soft-deleted rows still exist and are returned. Use findFirstOrThrow with a deletedAt: null filter, or add non-unique filters to the where clause if your generated client version supports them.