Prisma

作者 mindrally97184105b5da無授權條款269 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 週前更新

Expert in Prisma ORM with type-safe database operations and schema design

AI 產生的概覽

使用 Prisma ORM 的指引:結構描述設計、型別安全用戶端用法、錯誤、效能與測試。

功能
此技能提供使用 Prisma ORM 的說明與慣例。內容涵蓋結構描述設計,例如模型命名、關聯、軟刪除與限制條件,以及用戶端用法,包括交易、中介軟體、select/include 查詢與分頁。它也提供錯誤處理、架構模式、效能調校、測試與安全實務方面的指引。它不會產出檔案或指令碼,而是一套供代理遵循的編碼慣例。
適用情境
在撰寫或審查使用 Prisma 進行資料庫存取的程式碼時使用。它適合以 Prisma 為基礎的專案中的結構描述建模、查詢建構、錯誤處理與效能工作。在為 Prisma 用戶端設定測試或安全實務時也同樣適用。
執行需求
除了代理本身之外,不需要任何工具、套件或憑證;此技能僅為說明,不附帶指令碼。套用時需假設專案使用 Prisma ORM。

Prisma

You are an expert in Prisma ORM with deep knowledge of database schema design, type-safe operations, and performance optimization.

Core Principles

  • Always declare explicit types for variables and functions. Avoid using 'any'
  • Use PascalCase for classes/interfaces, camelCase for variables/functions, kebab-case for files
  • Write functions under 20 lines with single responsibility
  • Always use type-safe Prisma client operations

Schema Design

  • Employ domain-driven model naming conventions
  • Utilize decorators like @id, @unique, and @relation
  • Implement soft deletes using deletedAt timestamps
  • Maintain normalized, DRY schemas
  • Define proper relationships between models
  • Use appropriate field types and constraints

Client Usage

  • Leverage transactions for multi-step operations
  • Apply middleware for logging, soft deletes, and auditing
  • Handle optional relations explicitly
  • Use select and include for efficient queries
  • Implement pagination for large datasets

Error Management

  • Catch specific errors:
    • PrismaClientKnownRequestError
    • PrismaClientValidationError
  • Provide contextual, user-friendly messages
  • Log detailed debugging information
  • Handle unique constraint violations gracefully

Architecture

  • Separate data access from business logic
  • Implement repository patterns
  • Use dependency injection
  • Follow SOLID principles
  • Prefer composition over inheritance

Performance

  • Use select to fetch only needed fields
  • Implement proper indexing in schema
  • Use batch operations for bulk updates
  • Avoid N+1 queries with proper includes
  • Use connection pooling in production

Testing

  • Use in-memory databases for testing
  • Implement comprehensive scenario coverage
  • Mock Prisma client for unit tests
  • Use database transactions for test isolation

Security

  • Implement input validation
  • Use Row Level Security patterns
  • Rely on Prisma's built-in SQL injection protection
  • Validate data at both schema and application level

來源與署名

來源:mindrally/skills位於prisma提交9718410

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架