金色时刻 · 15:48
让好资源,触手可及
AGENT SKILL

database

database 是面向数据与分析、数据库、软件开发的 Agent Skill,来自 HoangNguyen0403/agent-skills-standard。查看技能说明、操作步骤与使用约定,并通过原项目了解详细用法。

Data access patterns, Scaling, Migrations, and ORM selection.

SKILL.md

下载 MD ↓
nameNestJS Database
descriptionData access patterns, Scaling, Migrations, and ORM selection.
metadata{"labels": ["nestjs", "database", "typeorm", "prisma", "mongodb"], "triggers": {"files": ["**/*.entity.ts", "prisma/schema.prisma"], "keywords": ["TypeOrmModule", "PrismaService", "MongooseModule", "Repository"]}}

NestJS Database Standards

Priority: P0 (FOUNDATIONAL)

Database integration patterns and ORM standards for NestJS applications.

Selection Strategy

See references/persistence_strategy.md for database selection matrix and scaling patterns (Connection Pooling, Sharding).

Patterns

  • Repository Pattern: Isolate database logic.
  • TypeORM: Inject @InjectRepository(Entity).
  • Prisma: Create a comprehensive PrismaService.
  • Abstraction: Services should call Repositories, not raw SQL queries.

Configuration (TypeORM)

  • Async Loading: Always use TypeOrmModule.forRootAsync to load secrets from ConfigService.
  • Sync: Set synchronize: false in production; use migrations instead.

Migrations

  • Never use synchronize: true in production.
  • Execution: Run via init container or CD step.
  • Zero-Downtime: Use Expand-Contract pattern (Add -> Backfill -> Drop).
  • Seeding: Use factories for dev data; only static dicts for prod.

Best Practices

  1. Pagination: Mandatory. Use limit/offset or cursor-based pagination.
  2. Indexing: Define indexes in code (decorators/schema) for frequently filtered columns (where, order by).
  3. Transactions: Use QueryRunner (TypeORM) or $transaction (Prisma) for all multi-step mutations to ensure atomicity.

来源:HoangNguyen0403/agent-skills-standard · MIT 许可 · 许可原文 · MD 为来源页保存的历史版本