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 從公開儲存庫中收錄這些內容。

檢舉或申請下架