Drizzle ORM
Overview
Drizzle is a headless, TypeScript-first ORM that stays close to SQL: you describe tables in TypeScript and write queries with a SQL-like fluent API. It is lightweight (~7.4kb minified+gzipped), tree-shakeable, and ships with zero dependencies, making it well suited to serverless and edge runtimes (Bun, Deno, Cloudflare Workers). Read this when you want type safety without a heavy abstraction layer over SQL.
Official sources
Install / setup
npm i drizzle-orm pg
npm i -D drizzle-kit @types/pg
Core concepts
- Schema in TypeScript: tables/columns are declared with helpers like
pgTable, giving full inference for queries.
- Two query styles: a SQL-like query builder (
select().from()...) and a relational queries API for ergonomic nested reads.
- drizzle-kit: the companion CLI for generating and applying migrations from your TS schema.
- Driver-agnostic: connect via the appropriate driver (node-postgres, postgres.js, MySQL, SQLite/libSQL, etc.).
- Headless / no codegen runtime: types come from your schema declarations, not a generated client.
Best practices
- Define schema in dedicated files and import them where queries run so types stay inferred end to end.
- Use
drizzle-kit generate to produce migration SQL and apply it with drizzle-kit migrate (per Drizzle docs) rather than hand-editing tables.
- Pick the query API to match the task: the query builder for explicit SQL, relational queries for nested fetches.
- Pin and review generated migrations in version control before applying to production.
Common pitfalls
- Expecting Prisma-style automatic client generation → Drizzle is headless; types derive from your schema declarations, so keep schema imports accurate.
- Mixing incompatible driver and dialect (e.g. a
pg driver with a MySQL schema) → choose the driver/dialect pair the docs specify for your database.
Examples
import { drizzle } from 'drizzle-orm/node-postgres'
import { pgTable, serial, text } from 'drizzle-orm/pg-core'
import { eq } from 'drizzle-orm'
export const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name'),
})
const db = drizzle(process.env.DATABASE_URL!)
const ada = await db.select().from(users).where(eq(users.name, 'Ada'))
Further reading
Related skills
- ../prisma — schema-DSL ORM with codegen alternative
- ../knex — lower-level SQL query builder
1---2name: drizzle3description: Lightweight, headless TypeScript-first SQL ORM with zero dependencies and SQL-like queries; consult for type-safe SQL in Node/edge runtimes.4domain: stack5category: orm6tags: [orm, typescript, nodejs, sql, serverless, postgresql]7official_sources:8 - https://orm.drizzle.team/docs/overview9 - https://github.com/drizzle-team/drizzle-orm10verified: 2026-06-1611metadata:12 source: https://skillmd.com/skills/gabriel7silva/drizzle13---1415# Drizzle ORM1617## Overview18Drizzle is a headless, TypeScript-first ORM that stays close to SQL: you describe tables in TypeScript and write queries with a SQL-like fluent API. It is lightweight (~7.4kb minified+gzipped), tree-shakeable, and ships with zero dependencies, making it well suited to serverless and edge runtimes (Bun, Deno, Cloudflare Workers). Read this when you want type safety without a heavy abstraction layer over SQL.1920## Official sources21- Docs: https://orm.drizzle.team/docs/overview22- Repo: https://github.com/drizzle-team/drizzle-orm23- Install / get started: https://orm.drizzle.team/docs/get-started2425## Install / setup26```bash27npm i drizzle-orm pg28npm i -D drizzle-kit @types/pg29```3031## Core concepts32- **Schema in TypeScript**: tables/columns are declared with helpers like `pgTable`, giving full inference for queries.33- **Two query styles**: a SQL-like query builder (`select().from()...`) and a relational queries API for ergonomic nested reads.34- **drizzle-kit**: the companion CLI for generating and applying migrations from your TS schema.35- **Driver-agnostic**: connect via the appropriate driver (node-postgres, postgres.js, MySQL, SQLite/libSQL, etc.).36- **Headless / no codegen runtime**: types come from your schema declarations, not a generated client.3738## Best practices39- Define schema in dedicated files and import them where queries run so types stay inferred end to end.40- Use `drizzle-kit generate` to produce migration SQL and apply it with `drizzle-kit migrate` (per Drizzle docs) rather than hand-editing tables.41- Pick the query API to match the task: the query builder for explicit SQL, relational queries for nested fetches.42- Pin and review generated migrations in version control before applying to production.4344## Common pitfalls45- Expecting Prisma-style automatic client generation → Drizzle is headless; types derive from your schema declarations, so keep schema imports accurate.46- Mixing incompatible driver and dialect (e.g. a `pg` driver with a MySQL schema) → choose the driver/dialect pair the docs specify for your database.4748## Examples49```ts50import { drizzle } from 'drizzle-orm/node-postgres'51import { pgTable, serial, text } from 'drizzle-orm/pg-core'52import { eq } from 'drizzle-orm'5354export const users = pgTable('users', {55 id: serial('id').primaryKey(),56 name: text('name'),57})5859const db = drizzle(process.env.DATABASE_URL!)60const ada = await db.select().from(users).where(eq(users.name, 'Ada'))61```6263## Further reading64- https://orm.drizzle.team/docs/migrations — migrations with drizzle-kit65- https://orm.drizzle.team/docs/rqb — relational queries API6667## Related skills68- ../prisma — schema-DSL ORM with codegen alternative69- ../knex — lower-level SQL query builder