본문으로 건너뛰기
cccskills
무료GitHub에 공개

prisma

TypeScript and Prisma ORM best practices for schema design, type-safe queries, migrations, and error handling. Use when writing Prisma schemas, building database access layers, or debugging query performance in TypeScript projects.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md4.2 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

prisma

Ensures Prisma code is type-safe, performant, and architecturally clean — covering the non-obvious patterns that trip up even experienced developers.

Core Principles

  • One PrismaClient per process. Multiple instances create multiple connection pools and exhaust your database connection limit.
  • Enums vs client imports. Import from the generated enums.ts in client/shared code; import from client.ts only in server-side code. Never import client.ts in client components.
  • Repository pattern. Keep data access logic separate from business logic. Create repository modules for complex query sets.
  • Transactions for multi-step writes. Any operation that modifies more than one record should use $transaction.
  • Never modify existing migrations. Treat migrations as append-only history.

When to Use

  • Writing or reviewing Prisma schema models
  • Building or refactoring a database access layer
  • Debugging N+1 queries or performance regressions
  • Setting up Prisma in a new project (especially Next.js)

Implementation Guide

Client Setup (Singleton)

The hot-reload guard is required in Next.js — without it, dev mode creates a new PrismaClient on every file change and exhausts connections:

// lib/prisma.ts
import { PrismaClient } from "@prisma/client";

const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };

export const prisma =
  globalForPrisma.prisma ?? new PrismaClient();

if (process.env.NODE_ENV !== "production")
  globalForPrisma.prisma = prisma;

Enums vs Client Imports

// ✅ Client component or shared validation code
import { Role, Status } from "@prisma/client/enums";

// ✅ Server-side only (API routes, server components, background jobs)
import { prisma } from "@/lib/prisma";
import type { User } from "@prisma/client";

// ❌ Never in client components
import { PrismaClient } from "@prisma/client";

Schema Design

  • Use domain-driven model names. Keep schemas normalized and DRY.
  • Declare all relations explicitly with @relation.
  • Implement soft delete via deletedAt DateTime? — never hard-delete records that may be referenced.
  • Use Prisma's native type decorators for database-level precision.

Queries & Performance

  • N+1: Use nested include or select instead of looping with separate queries.
  • Pagination: Use take and skip; add a cursor-based approach for large datasets.
  • Field selection: Use select to fetch only needed fields; avoid over-fetching with blanket include.
  • Join strategy: relationLoadStrategy ("join" or "query") is available but requires enabling the relationJoins preview feature flag. "join" uses a single LATERAL JOIN; "query" sends one query per table and joins at the application level.

Error Handling

Catch Prisma-specific errors at the repository boundary:

  • PrismaClientKnownRequestError — structured DB errors. Check error.code:
    • P2002 — unique constraint violation
    • P2025 — record not found (replaces the removed NotFoundError from Prisma 5)
  • PrismaClientUnknownRequestError — unstructured DB errors
  • PrismaClientValidationError — invalid query shape (usually a type error)

Provide user-friendly messages upstream; log the full error with context for debugging.

Migrations

  • Use descriptive names: prisma migrate dev --name add_user_email_index.
  • Review generated SQL before applying to production.
  • Never edit existing migration files — create a new migration instead.
  • Keep migrations idempotent where possible.

Review Checklist

  • Is there a single PrismaClient instance with the hot-reload guard in place?
  • Are enums imported from enums.ts in any client or shared code?
  • Do multi-record writes use $transaction?
  • Are N+1 patterns avoided (no DB calls inside loops)?
  • Are PrismaClientKnownRequestError codes handled at the repository boundary?
  • Do migrations have descriptive names and remain unmodified after creation?

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

adhd

무료

Formats output for ADHD-friendly action — lead with the next step, number tasks, restate state, cut fluff. Use when named (adhd), when the user mentions ADHD or focus/executive-function constraints, or when they ask for steps they can execute immediately.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nateslabach/skills62026년 9월 29일 업데이트

Devil's-advocate attack on AI workflow designs — threat model, assumption challenges, code critiques, and hypothetical redesigns with no file edits. Use for "attack this design", devil's advocate, or hostile challenge on agents/tools/summarization/tokens. Not for PR peer review (code-review) or self-review that applies fixes (ai-systems-review). Prefer: this skill → decide → ai-systems-review.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nateslabach/skills62026년 9월 29일 업데이트

Hostile self-review of recently written AI workflow code that then applies fixes (agents, tools, chat context, summarization, tokens, attachments). Use after generating AI systems code, or when asked to self-review and harden it. Not for PR peer review (code-review) or no-edit devil's-advocate attacks (adversarial-challenge). Prefer: adversarial-challenge → decide → this skill.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nateslabach/skills62026년 9월 29일 업데이트

Writes in ASD-STE100 simplified technical English — short sentences, plain words, active voice. Use when the user wants terse technical prose, names this skill, or asks for STE100.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nateslabach/skills62026년 9월 29일 업데이트

branding

무료

Builds personal brand assets using Seth Godin's frameworks: signature symbol, slogan, surprise (Purple Cow), salient idea, and signature story. Use when named (branding), or when the user asks for a brand symbol, slogan, tagline, Purple Cow, counterintuitive angle, core idea, brand story, or personal brand positioning.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nateslabach/skills62026년 9월 29일 업데이트

Disables the AI's default hedging, diplomatic softening, and social-nicety layers to deliver cold, unfiltered, consequentialist analysis on any topic. Use when the user wants the AI's actual assessment without padding, regardless of how harsh or uncomfortable the honest answer is.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nateslabach/skills62026년 9월 29일 업데이트

nateslabach의 스킬 모두 보기

이 스킬의 문제 신고