drizzle-best-practices
Skill21 starsChanged 11 days agoMITView on GitHub
Use this skill whenever the user is working with Drizzle ORM on PostgreSQL. This covers any mention of Drizzle, drizzle-orm, drizzle-kit, drizzle-zod, `pgTable`, `defineRelations`, `relations()`, `db.select()`, `db.query`, or insert/update/delete against Postgres.
- Installs packages
1 other project uses a version of this.
Adopted by
Most recently taken up by
- eleven-labs/skillstheir own version, first seen Feb 23, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- eleven-labs/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository16 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .agents/skills/drizzle-best-practices/AGENTS.mdAGENTS.md
- .agents/skills/vercel-composition-patterns/AGENTS.mdAGENTS.md
- .agents/skills/drizzle-best-practices/CLAUDE.mdCLAUDE.md
- frontend-designSkill
- honoSkill
- openspec-apply-changeSkill
- openspec-archive-changeSkill
- openspec-exploreSkill
- openspec-proposeSkill
- openspec-sync-specsSkill
- pnpmSkill
- vercel-composition-patternsSkill
- viteSkill
- vitestSkill
- oneselfSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 63
When the version is unstated, default to v1 (RC) for new code, but match the existing codebase's API if you already see legacy relations() …
- Distinctive: line 95
Read individual reference files for detailed explanations and code examples:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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.
Version & API Detection (read this first)
Drizzle is mid-transition to v1, and the relations + relational-query APIs differ between
the two major lines. Check the project's package.json before writing code so you emit the
right syntax:
Installed drizzle-orm | API to use | Install command |
^1.0.0-rc or ^1.0.0-beta | v1 — the default in this skill. defineRelations, object-syntax relational queries (where: { … }, orderBy: { … }), validators from drizzle-orm/zod | npm i drizzle-orm@rc + npm i -D drizzle-kit@rc |
^0.4x (e.g. 0.45.2) | Legacy. relations() helper, callback/operator relational queries, validators from the separate drizzle-zod package | npm i drizzle-orm (resolves to 0.45.2) |
The current release candidate is drizzle-orm@1.0.0-rc.3 (the @rc tag), which supersedes the
older @beta tag the docs still reference in places.
Three things that routinely trip up agents:
@latestis still0.45.2, not v1.npm i drizzle-ormdoes not get you v1 — a new project that wants the v1 API must ask for@rcexplicitly.- The SQL-like query builder is unchanged across versions.
db.select().from(t).where(eq(t.id, 1)),db.insert(),db.update(),db.delete()work identically in 0.45.x and v1. Only the relational query API (db.query) and relation definitions changed. Never rewritedb.select()operator filters into the relational object syntax. - On v1, the relational query API (
db.query) is driven bydefineRelations. Passing a legacyschemadoes not populatedb.query. The oldrelations()helper is still importable fromdrizzle-orm/_relationsso existing relation modules keep compiling during a port, but to query relationally on v1 you convert them todefineRelations. (Earlier betas exposed adb._querypath; it was removed before1.0.0-rc.3.) Seereferences/relations-defining.md.
When the version is unstated, default to v1 (RC) for new code, but match the existing codebase's
API if you already see legacy relations() / callback-style db.query patterns in use. Throughout
the reference files, version-specific differences are marked with "Legacy (v0.45.x)" callouts.
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
defineRelationsor the legacyrelationsAPI - Configuring
drizzle-kitfor 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 referencesEach 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
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

