honra-io

drizzle-best-practices

Drizzle ORM best practices for TypeScript projects using PostgreSQL. Use this skill when writing, reviewing, or optimizing Drizzle ORM schemas, queries, relations, migrations, or database configurations targeting Postgres. Apply these guidelines whenever you see drizzle-orm imports, pgTable definitions, drizzle-kit config files, or relational query patterns. Also use when setting up a new project with Drizzle + Postgres, migrating from another ORM, or troubleshooting type errors in Drizzle schemas.

honra-io 11 Updated 3mo ago
GitHub

Install

npx skillscat add honra-io/drizzle-best-practices

Install via the SkillsCat registry.

SKILL.md

Drizzle ORM Best Practices (PostgreSQL)

Comprehensive best practices guide for Drizzle ORM with PostgreSQL. Contains guidance across
8 categories, prioritized by impact to help you write correct, performant, and maintainable
database code.

When to Apply

Reference these guidelines when:

  • Defining table schemas with pgTable
  • Writing select, insert, update, or delete queries
  • Setting up relations between tables using defineRelations or the legacy relations API
  • Configuring drizzle-kit for migrations (generate, push, pull)
  • Inferring TypeScript types from your schema
  • Choosing between the SQL-like API and the relational query API
  • Optimizing query performance with prepared statements or batch operations
  • Integrating Drizzle with serverless Postgres providers (Neon, Supabase, etc.)

Rule Categories by Priority

Priority Category Impact Prefix
1 Schema Design CRITICAL schema-
2 Query Patterns CRITICAL query-
3 Relations HIGH relations-
4 Migrations HIGH migrations-
5 Type Safety MEDIUM-HIGH types-
6 Performance MEDIUM perf-
7 Database Drivers MEDIUM driver-
8 Advanced Patterns LOW advanced-

How to Use

Read individual reference files for detailed explanations and code examples:

references/engine-postgres.md          # Postgres-specific types, features, and patterns
references/schema-table-definitions.md
references/query-select-patterns.md
references/relations-defining.md
references/_sections.md                # Full index of all references

Each reference file contains:

  • Brief explanation of why it matters
  • Incorrect code example with explanation
  • Correct code example with explanation
  • Links to official Drizzle documentation

References