AGENT SKILL

drizzle

Rules, standards, and references for Drizzle ORM query styles, performance optimization, type safety, and Drizzle Kit CLI/MCP tooling automation. Use when writing Drizzle queries, defining database services, or configuring migration automation.

License 许可
MIT
最近更新
2026-08-02
Stars
★ 0
Forks
0

01 前言 Front Matter

name
drizzle
license
MIT
metadata
{ "author": "ngxc", "version": "1.1.0" }
description
Rules, standards, and references for Drizzle ORM query styles, performance optimization, type safety, and Drizzle Kit CLI/MCP tooling automation. Use when writing Drizzle queries, defining database services, or configuring migration automation.
argument-hint
[--table <string>] [--query-type <string>]

02 资源文件 15

03 SKILL.md 正文

Drizzle ORM Best Practices

Comprehensive guide for writing type-safe, high-performance database queries and services using Drizzle ORM and Drizzle Kit. Contains 14 rules across 8 categories, prioritized by impact from critical (setup, schemas, type safety) to high/medium (query selection, performance, tooling automation).

When to Apply

Reference these guidelines when:

  • Defining database services and interfaces.
  • Writing read/write operations with Drizzle ORM.
  • Designing Data Transfer Objects (DTOs) and API boundary types.
  • Deciding between Drizzle Relational Queries (db.query) and Core SQL Queries (db.select).
  • Handling database query failures and non-existent records.
  • Automating database migrations with Drizzle Kit CLI, SDK, or MCP server.

Rule Categories by Priority

Priority Category Impact Prefix Rules
1 DTO & Schema Isolation CRITICAL dto- 1
2 Type Safety & Unions CRITICAL type- 1
3 Transactions & Locking CRITICAL lock- 1
4 Schema & Relations Config CRITICAL schema-, relations- 2
5 Query Selection & YAGNI HIGH select- 3
6 Query Style & Performance HIGH style- 4
7 Error Handling MEDIUM error- 1
8 Tooling & MCP Automation HIGH drizzle-kit- 1

Quick Reference

1. DTO & Schema Isolation (CRITICAL)

  • dto-omit-for-objects - Define DTOs using Omit on Object types to isolate database schemas from presentation layers.

2. Type Safety & Unions (CRITICAL)

  • type-union-exclude - Use Exclude for filtering string literal union types and Omit for object types.

3. Transactions & Locking (CRITICAL)

  • lock-pessimistic-row - Use pessimistic row locking in transactions to prevent concurrent write hazards.

4. Schema & Relations Config (CRITICAL)

  • schema-creation - Use snakeCase.table for automatic case conversion and mix in baseEntity/fullEntity helpers.
  • relations-configuration - Centralize table relations using defineRelations with explicit from, to, optional, and alias parameters.

5. Query Selection & YAGNI (HIGH)

6. Query Style & Performance (HIGH)

  • style-query-vs-select - Prefer Core select queries for flat lookups and Relational queries for deeply nested relation hydration.
  • style-where-sql-expression - Never pass raw SQL expressions directly to Relational Query where clauses.
  • style-conditional-aggregation - Use conditional aggregation via CASE WHEN to consolidate multiple aggregate queries into a single query.
  • style-typed-sql-nullable - Use type-safe mapWith() callbacks and chain .nullable() on raw SQL expressions to preserve nullability.

7. Error Handling (MEDIUM)

8. Tooling & MCP Automation (HIGH)

  • drizzle-kit-cli-mcp - Automate migration workflows with --output json, --hints, @drizzle-kit/cli SDK, and stdio MCP server (drizzle-kit mcp).

How to Use

Read individual reference files for detailed guidelines, configurations, and code examples:

Full Compiled Document

For the complete guide with all rules expanded: AGENTS.md

References

04 同仓库更多 Skills

ngxccc
ngxccc/agent-skills-kit

zustand

Rules and standards for state management using Zustand in React and Next.js. Use when implementing client-side stores, persistence with localStorage, or preventing SSR hydration mismatch.

★ 0
ngxccc
ngxccc/agent-skills-kit

zod

Zod v4 schema validation best practices. Use when defining schemas, utilizing safeParse, or customizing error messages.

★ 0
ngxccc
ngxccc/agent-skills-kit

upstash-ratelimit

Rules, standards, and references for rate limiting in serverless environments using Upstash Ratelimit. Use when implementing rate limiting, configuring Upstash Redis, or handling request blocking.

★ 0
ngxccc
ngxccc/agent-skills-kit

ui-design

UI/UX and frontend design best practices guidelines (formerly frontend-design). This skill should be used when writing, reviewing, or designing frontend code to ensure accessibility, performance, and usability. Triggers on tasks involving HTML structure, CSS styling, responsive layouts, form design, animations, or accessibility improvements.

★ 0
ngxccc
ngxccc/agent-skills-kit

typescript

TypeScript performance, tsconfig, type errors, async patterns — triggered when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.

★ 0
ngxccc
ngxccc/agent-skills-kit

typescript-refactor

TypeScript and TSX refactoring and modernization guidelines from a principal specialist perspective, current to TypeScript 6.0 and React 19. This skill should be used when refactoring, reviewing, or modernizing TypeScript or React/TSX code for type safety, compiler performance, and idiomatic patterns. Triggers on tasks involving type architecture, narrowing, generics, discriminated unions, error handling, React component and hook typing, or migration to modern TypeScript features (satisfies, using, const type parameters, inferred type predicates, isolatedDeclarations, erasable syntax, import attributes).

★ 0