prisma_orm

Implements Prisma ORM query, transaction, and repository patterns for TypeScript database access.

Updated Jan 14, 2026
One-click install
npx skills add https://github.com/jvsandhu/agentic-skills --skill prisma-orm-jvsandhu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: prisma_orm
Source: https://github.com/jvsandhu/agentic-skills/tree/main/skills/prisma_orm
Command: npx skills add https://github.com/jvsandhu/agentic-skills --skill prisma-orm-jvsandhu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @prisma/client.

What problem does it solve? Writing Prisma database code often leads to N+1 query problems, unoptimized field selection, inconsistent error handling, and scattered data access logic. This Skill provides proven patterns for structuring Prisma Client usage so database operations stay performant, type-safe, and maintainable. ## Core Features & Use Cases - Query & Relation Patterns: Covers findUnique, findMany, complex AND/OR filtering, nested writes, and one-to-many relation loading with include and select. - Transaction & Error Handling: Demonstrates interactive $transaction usage with timeouts and mapping Prisma error codes (P2002, P2003, P2025) to domain exceptions. - Performance Optimization: Shows how to prevent N+1 queries via include or batched where-in queries, limit fields with select, and use aggregations, groupBy, and upsert. - Use Case: When building a NestJS or Node.js service, apply the repository template to centralize user data access, wrap multi-step writes in transactions, and avoid N+1 queries when loading user profiles. ## Quick Start Ask the agent to refactor a service that fetches users and their profiles so it uses a Prisma repository with include-based N+1 prevention and proper P2002 error handling.

Frequently Asked Questions about prisma_orm

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

FAQPage Schema
How do I prevent N+1 queries in Prisma?

Prevent N+1 queries in Prisma by using include to fetch relations in a single query, or by batching: collect IDs from the first query and fetch related records with where: { id: { in: ids } }. Never call findUnique inside a loop over results.

How to handle Prisma unique constraint errors in TypeScript?

Catch Prisma.PrismaClientKnownRequestError and check the error code. P2002 indicates a unique constraint violation, P2003 a foreign key failure, and P2025 a missing record. Map each code to a domain error like ConflictError or NotFoundError.

When should I use the repository pattern with Prisma?

Use a repository when queries involve complex joins or includes, are reused in multiple places, or need mocking for tests. Skip it for simple one-off queries or prototypes where direct Prisma Client calls are sufficient.

Does Prisma support interactive transactions with timeouts?

Yes, Prisma supports interactive transactions via $transaction(async (tx) => {...}) with options like maxWait and timeout in milliseconds. All operations inside the callback share the transaction client and roll back together on failure.

Why is using select better than fetching all fields in Prisma?

Using select limits the query to only required fields, reducing data transfer and memory usage. It also works with relations, letting you pick specific nested fields instead of loading entire related records with include.