用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/majiayu000/claude-skill-registry-data --skill api-database-prisma命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Guided, hands-on course teaching architects how to use Claude Code — six short modules, each built around an exercise on a bundled sandbox project (a fictional Brooklyn art museum expansion). Resumable across sessions via PROGRESS.md. Use when the user runs /learn, says they're new to Claude Code, or asks how to learn it.
Upscale and restore video in ComfyUI — both the quick local path (per-frame ESRGAN like 4x_foolhardy_Remacri via ImageUpscaleWithModel + 4x→2x supersample, with its temporal-flicker tradeoff) and temporal-aware super-resolution (SeedVR2, the newer FlashVSR) with the downscale-first restore pipeline; RIFE/FILM frame interpolation via the BUILT-IN ComfyUI 0.26 FrameInterpolate (rife_v4.26 in models/frame_interpolation/) or the ComfyUI-Frame-Interpolation pack; 2x/4x scaling, VRAM tiers, VHS encode. Captures the classic downscale→SeedVR2→RIFE recipe and the current 2026 recommendation.
Auto-tag FF&E products with categories, colors, materials, and style tags using AI. Use when the user asks to "enrich", "tag", or "categorize" products, or to fill in missing category, material, or style columns in the schedule.
正在显示 SKILL.md
基于 SOC 职业分类
| name | api-database-prisma |
| description | Prisma ORM, type-safe queries, migrations, relations |
Quick Guide: Use Prisma ORM for type-safe database queries with auto-generated TypeScript types. Schema-first design with declarative migrations. Use
includefor relations,$transactionfor atomic operations. Singleton pattern required in development to avoid connection exhaustion. Always usetx(notprisma) inside interactive transaction callbacks.
<critical_requirements>
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST use the singleton pattern for PrismaClient in development to prevent connection exhaustion from hot reloading)
(You MUST use tx parameter (NOT prisma) inside interactive transaction callbacks to ensure atomicity)
(You MUST use include or nested select for relational queries - avoid N+1 by fetching relations in the same query)
(You MUST define @relation with explicit fields and references for all foreign key relationships)
</critical_requirements>
Auto-detection: prisma, @prisma/client, PrismaClient, prisma.schema, prisma migrate, findUnique, findMany, include, $transaction
When to use:
When NOT to use:
Key patterns covered:
include and nested selectDetailed Resources:
Prisma ORM provides a declarative schema language that generates type-safe database clients. The schema serves as the single source of truth for your data model, TypeScript types, and migrations.
Core principles:
schema.prisma, generate everything elseprisma.user.findMany())Use singleton pattern to prevent connection pool exhaustion during development hot reloading. Without this, each hot reload creates a new PrismaClient with its own connection pool, quickly exhausting database connections.
// lib/db/client.ts
import { PrismaClient } from "@prisma/client";
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
};
const createPrismaClient = () => {
return new PrismaClient({
log:
process.env.NODE_ENV === "development"
? ["query", "error", "warn"]
: ["error"],
});
};
export const prisma = globalForPrisma.prisma ?? createPrismaClient();
if (process.env.NODE_ENV !== "production") {
globalForPrisma.prisma = prisma;
}
Why good: globalThis persists across hot reloads, conditional logging avoids production noise
// BAD: New client every import
export const prisma = new PrismaClient(); // New instance on every hot reload
Why bad: Exhausts database connections (default 100 for PostgreSQL) after repeated hot reloads
See examples/core.md for serverless connection patterns.
Define models with relations, constraints, and defaults. The schema is the source of truth.
model User {
id String @id @default(cuid())
email String @unique
name String?
role Role @default(USER)
posts Post[]
profile Profile?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("users")
}
model Post {
id String @id @default(cuid())
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([authorId])
@@map("posts")
}
Why good: cuid() for collision-resistant IDs, @updatedAt auto-tracks changes, @relation with onDelete: Cascade prevents orphans, @@index on foreign keys, @@map for snake_case DB tables with PascalCase in code
All queries are fully typed based on your schema. Key operations:
const DEFAULT_PAGE_SIZE = 20;
const MAX_PAGE_SIZE = 100;
// Find by unique field - returns T | null
const user = await prisma.user.findUnique({
where: { email: "alice@example.com" },
});
// Find many with filters + pagination
const users = await prisma.user.findMany({
where: {
role: { in: ["USER", "MODERATOR"] },
createdAt: { gte: new Date("2024-01-01") },
},
orderBy: { name: "asc" },
take: DEFAULT_PAGE_SIZE,
});
// Upsert - atomic create-or-update
const upserted = await prisma.user.upsert({
where: { email: "alice@example.com" },
create: { email: "alice@example.com", name: "Alice" },
update: { name: "Alice Updated" },
});
Why good: Type-safe operations catch errors at compile time, findUnique returns T | null forcing null handling, upsert is atomic
See examples/core.md for complete CRUD operations, filtering, and pagination patterns.
Fetch related data efficiently using include or nested select to avoid N+1 queries.
// Include related records - single query
const userWithPosts = await prisma.user.findUnique({
where: { id: userId },
include: {
posts: {
where: { published: true },
orderBy: { createdAt: "desc" },
take: 10,
},
profile: true,
},
});
// Select specific fields only - smaller payload
const userSummary = await prisma.user.findUnique({
where: { id: userId },
select: {
id: true,
name: true,
posts: { select: { id: true, title: true } },
},
});
Why good: Single query avoids N+1, include fetches all fields, select reduces payload
// BAD: N+1 query pattern
const users = await prisma.user.findMany();
for (const user of users) {
const posts = await prisma.post.findMany({
where: { authorId: user.id },
}); // N additional queries!
}
Why bad: 1 query for users + N queries for posts, extremely slow at scale
See examples/relations.md for relation filters, many-to-many, self-relations, and include vs select patterns.
Ensure atomic operations across multiple writes.
// Nested writes - implicit transaction
const user = await prisma.user.create({
data: {
email: "alice@example.com",
name: "Alice",
profile: { create: { bio: "Developer" } },
posts: { create: [{ title: "First Post", published: true }] },
},
include: { profile: true, posts: true },
});
// Interactive transaction - complex logic with rollback
const MINIMUM_BALANCE = 0;
const transferFunds = async (fromId: string, toId: string, amount: number) => {
return await prisma.$transaction(async (tx) => {
const sender = await tx.account.update({
where: { id: fromId },
data: { balance: { decrement: amount } },
});
if (sender.balance < ) {
();
}
tx..({
: { : toId },
: { : { : amount } },
});
});
};
Why good: Nested writes are cleanest for related records, interactive transactions enable business logic with automatic rollback
// BAD: Using prisma instead of tx
await prisma.$transaction(async (tx) => {
await prisma.post.create({ data: { title: "Post" } }); // Uses prisma, not tx!
});
Why bad: Operations using prisma bypass transaction context, won't rollback on failure
See examples/transactions.md for batch transactions, error handling, optimistic concurrency, and transaction options.
Handle connections properly for different environments.
// Graceful shutdown
process.on("beforeExit", async () => {
await prisma.$disconnect();
});
// Serverless: use connection pooler (PgBouncer, Prisma Accelerate)
export const prisma = new PrismaClient({
datasources: {
db: { url: process.env.DATABASE_URL_WITH_POOLER },
},
});
Why good: Graceful shutdown prevents connection leaks, connection pooler handles serverless connection management
<red_flags>
High Priority Issues:
prisma instead of tx in interactive transactions - bypasses transaction contextinclude or select instead@relation attributes - ambiguous foreign keys cause migration errorsMedium Priority Issues:
onDelete cascade - orphaned records when parent deletedinclude when only some needed - use selectGotchas & Edge Cases:
createMany doesn't return created records (use createManyAndReturn on PostgreSQL/CockroachDB/SQLite)updateMany and deleteMany don't trigger @updatedAt hooksJson fields are typed as JsonValue - need runtime validation at parse boundaryDecimal fields return Prisma.Decimal type - convert with .toNumber()timeout optionfindFirst without orderBy returns non-deterministic results</red_flags>
<critical_reminders>
All code must follow project conventions in CLAUDE.md
(You MUST use the singleton pattern for PrismaClient in development to prevent connection exhaustion from hot reloading)
(You MUST use tx parameter (NOT prisma) inside interactive transaction callbacks to ensure atomicity)
(You MUST use include or nested select for relational queries - avoid N+1 by fetching relations in the same query)
(You MUST define @relation with explicit fields and references for all foreign key relationships)
Failure to follow these rules will exhaust database connections, break transaction atomicity, cause N+1 performance problems, and create unclear relation definitions.
</critical_reminders>