Prisma Development

mindrally/skills/prisma-development

作者 mindrally97184105b5da无许可证269 个星标收录于 2026年10月8日更新于 2026年10月8日仓库5周前更新

Comprehensive Prisma ORM development guidelines with TypeScript, schema design, migrations, and best practices.

AI 生成的概览

面向 TypeScript 的 Prisma ORM 开发规范,涵盖模式设计、客户端使用、迁移与错误处理。

功能
该技能为在 TypeScript 项目中使用 Prisma ORM 提供一套开发规范。内容涵盖 TypeScript 约定、函数设计、数据与错误处理、Prisma 模式设计、客户端使用、迁移以及质量标准。它仅提供指导性说明,不附带任何脚本或资源。
适用场景
适用于在 TypeScript 代码库中编写、审查或重构基于 Prisma 的数据访问代码时。也适用于设计 Prisma 模式、规划迁移或处理 Prisma 客户端错误时。
运行要求
无需任何工具、软件包或凭据;该技能仅为说明性内容,不附带脚本。

Prisma ORM Development

You are an expert in Prisma ORM development with TypeScript.

TypeScript Fundamentals

Basic Principles

  • Always declare explicit types for variables and functions
  • Avoid using 'any'
  • Leverage JSDoc for public APIs
  • Maintain single exports per file
  • Prioritize self-documenting code

Naming Conventions

  • PascalCase for classes/interfaces
  • camelCase for variables and methods
  • kebab-case for files/directories
  • UPPERCASE for constants
  • Verb-based boolean names (isLoading, hasError, canDelete)

Function Design

  • Aim for less than 20 lines of code per function
  • Single responsibility per function
  • Implement early returns
  • Extract complex logic into separate functions
  • Leverage functional patterns (map, filter, reduce)
  • Use object parameters for multiple arguments

Data & Error Handling

  • Encapsulate data in composite types with immutability preference
  • Use readonly and as const appropriately
  • Validate at boundaries
  • Employ specific, descriptive error types with contextual messaging

Prisma-Specific Practices

Schema Design

  • Domain-driven naming for models and fields
  • Explicit relations using @relation
  • Normalized structures where appropriate
  • Soft deletes via deletedAt field
  • Native type decorators for database-specific types

Client Usage

  • Always use type-safe Prisma client operations
  • Use transactions for complex flows
  • Implement middleware for logging, soft deletes, and auditing
  • Use select and include judiciously to avoid over-fetching

Migrations

  • Create descriptive migrations with clear naming
  • Never modify existing migrations
  • Ensure idempotency for all migrations
  • Test migrations on staging before production

Error Handling

  • Catch PrismaClientKnownRequestError for constraint violations
  • Handle PrismaClientUnknownRequestError for unexpected database errors
  • Validate with PrismaClientValidationError for schema mismatches

Quality Standards

  • Avoid N+1 queries through proper eager loading
  • Test with in-memory databases for speed
  • Mock Prisma client for unit test isolation
  • Never expose raw Prisma clients in APIs
  • Validate all user inputs before database operations
  • Follow SOLID principles with composition over inheritance

来源与署名

来源:mindrally/skills位于prisma-development提交9718410

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架