drizzle
Drizzle ORM
Drizzle ORM is a lightweight, TypeScript-first ORM with a SQL-like query builder, schema-as-code migrations, and zero dependencies.
Documentation
Key Capabilities
Built-in schema validation adapters — Drizzle includes first-party integrations with Zod, Valibot, TypeBox, ArkType, and Effect Schema via drizzle-zod, drizzle-valibot, etc. There is no need to manually write validation schemas that mirror your table definitions; these packages infer insert/select types directly from your Drizzle schema.
Built-in seeding — drizzle-seed provides deterministic, reproducible fake data generation with seedable PRNG, weighted distributions, and cross-dialect support. It replaces ad-hoc seed scripts or external packages like @faker-js/faker for database seeding workflows.
Best Practices
Call .$dynamic() to compose queries across functions. By default, Drizzle query builders restrict each clause method (where, limit, orderBy) to a single call — this mirrors SQL but breaks composable helper functions. You must call .$dynamic() to unlock multi-call mode. Use the dialect-specific generic types (PgSelect, MySqlSelect, SQLiteSelect) as parameter types for functions that accept a query builder to extend.
Relational queries (db.query.*) generate exactly one SQL statement — nested offset is not supported. Unlike Prisma's batched-query approach, Drizzle uses a single lateral-join query per db.query call. A consequence is that offset only works at the top level of a relational query; nested relation pagination must use where with cursor-based logic instead.
Use drizzle-kit push only for development, never production. drizzle-kit push applies schema changes directly without generating migration files. Teams that use push in production lose the auditable migration history needed for drizzle-kit migrate in CI/CD. Use drizzle-kit generate + drizzle-kit migrate for production deployments.
Never instantiate drizzle() per request in serverless environments. Each call can open a new connection pool. Export a module-level singleton and re-use it across invocations, following the same pattern as Prisma's PrismaClient singleton pattern.
drizzle-kit pull and push do not preserve hand-written SQL in migration files. If you manually edit a generated migration file (e.g., to add a partial index or a custom trigger), subsequent pull operations will overwrite those edits. Track custom migrations in separate numbered files and apply them alongside generated ones.
db.query.* relational queries require explicit relations() definitions. Unlike Prisma, Drizzle does not infer relations from foreign keys automatically. If you call db.query.users.findMany({ with: { posts: true } }) without a relations() export in the schema file, the query throws at runtime with a non-obvious error. Define relations explicitly for every table you want to query relationally.
More from mikkelkrogsholm/dev-skills
meilisearch
Meilisearch — fast, open-source search engine with typo tolerance, faceted search, and AI-powered hybrid search. Use when building with Meilisearch or asking about its index configuration, search parameters, filters, facets, API keys, geosearch, ranking rules, or integration with JavaScript/TypeScript clients. Fetch live documentation for up-to-date details.
42shadcn-ui
shadcn/ui — copy-owned React component library built on Radix UI and Tailwind CSS. Use when building with shadcn/ui or asking about its components, CLI, theming, configuration, or integration with Next.js, Vite, Remix, or other frameworks. Fetch live documentation for up-to-date details.
10zod
Zod — TypeScript-first schema validation with static type inference. Use when building with Zod or asking about schema definitions, type inference, parsing, transformations, refinements, coercion, error handling, or integration with forms, APIs, or tRPC. Fetch live documentation for up-to-date details.
10bun
Bun — fast all-in-one JavaScript/TypeScript runtime, package manager, bundler, and test runner. Use when building with Bun, running TypeScript, managing packages with bun install, writing tests with bun test, or asking about Bun APIs, configuration, or Node.js migration. Fetch live documentation for up-to-date API details.
9better-auth
Better Auth — framework-agnostic authentication and authorization framework for TypeScript. Use when building with Better Auth or asking about its APIs, configuration, plugins, session management, OAuth, or integration. Fetch live documentation for up-to-date details.
7react
React — JavaScript library for building user interfaces with components. Use when building with React or asking about hooks, state management, effects, Server Components, Suspense, or any React APIs, patterns, or configuration. Fetch live documentation for up-to-date details.
7