- Home
- Skills
- Joncrangle
- .Dotfiles
- Drizzle Orm
drizzle-orm_skill
- TypeScript
8
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill joncrangle/.dotfiles --skill drizzle-orm- SKILL.md8.3 KB
Overview
This skill provides a concise guide to using Drizzle ORM with TypeScript for type-safe SQL queries, schema definitions, migrations, and relations. It explains setup, common patterns, and integration points for Next.js and Node.js projects. The focus is practical: get a typed database layer, run migrations, and write safe queries with great developer experience.
How this skill works
Drizzle maps TypeScript schema definitions to SQL tables and generates typed query helpers so queries and results are fully typed. It uses small driver adapters (Postgres, MySQL, SQLite, Neon, etc.) and a separate drizzle-kit for generating and applying migrations. Relations, transactions, and query helpers (eq, and, like, sql, etc.) make complex queries and server actions straightforward and type-safe.
When to use it
- Building a database layer in Next.js or Node.js with TypeScript
- When you want compile-time types for queries and results
- Implementing relations and cascading foreign keys in a relational schema
- Needing lightweight, performant ORM without runtime heavy abstractions
- Managing migrations and schema drift with a simple CLI (drizzle-kit)
Best practices
- Define a single schema file and export typed table objects for reuse across the app
- Keep DB connection code separate (src/db/index.ts) and inject or import a single db instance
- Use drizzle-kit to generate migrations and keep migration files in source control
- Prefer transactions for multi-step operations that must be atomic
- Use relation helpers to model associations and avoid manual join logic where possible
- Use index definitions on frequently queried columns to improve performance
Example use cases
- Next.js server actions that perform create/read/update/delete with immediate cache revalidation
- An API service with typed queries for tasks, users, and related resources
- Batch imports and background jobs using transactions to keep data consistent
- Feature work requiring complex filters, full-text or case-insensitive queries using query helpers
- Local dev with SQLite and CI/production with Postgres using the same schema code
FAQ
Use drizzle-kit (installed as a dev dependency) to generate, apply, and push migrations. It integrates with the same schema file you use in code.
How do I switch database drivers between environments?
Export a single db connector factory that selects the proper driver based on environment variables (e.g., Neon for serverless, pg for node-postgres, better-sqlite3 for local). The rest of the app uses the same typed db instance.
Can I use relations in queries?
Yes. Define relations with the relations helper and use db.query.<table>.findMany/findFirst with the with option to load related rows in a typed way.