Drizzle ORM

A lightweight, zero-dependency TypeScript ORM with full SQL-like query flexibility

Library
npm
v0.45.3
35,907 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
79 /100 Good
Development Activity 76
Maintenance 76
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
81 /100 Excellent
Architecture 90
Code Quality 82
Innovation 85
Learning Curve 68

Drizzle ORM is a TypeScript-first ORM and SQL query builder built around the idea that you should never have to leave SQL-like syntax to get type safety. It ships as a headless, ~7.4kb library with zero runtime dependencies, and supports PostgreSQL, MySQL, SQLite, and SingleStore across every major JavaScript runtime, including Node.js, Bun, Deno, Cloudflare Workers, and edge functions.

Rather than hiding the database behind a heavyweight abstraction, Drizzle lets you declare schemas in TypeScript and then either write relational queries (similar to an ORM) or SQL-like queries (similar to a query builder), both fully typed end to end. Its companion CLI, Drizzle Kit, handles migrations, and Drizzle Studio provides a GUI for browsing and editing data, giving teams a complete, serverless-ready toolkit without generated clients or Rust binaries.

What You Get

  • A ~7.4kb, zero-runtime-dependency core library that stays tree-shakeable and works in serverless/edge runtimes
  • Type-safe schema declarations that double as the source of truth for both migrations and query type inference
  • Two query APIs in one library: a chained SQL-style builder and a relational-query API (db.query.table.findMany())
  • Drizzle Kit, a companion CLI for generating and applying SQL migrations from your TypeScript schema
  • Drizzle Studio, a GUI for browsing and editing data across any supported database
  • First-class drivers for PostgreSQL, MySQL, SQLite, and SingleStore, plus serverless-specific adapters for Neon, Turso, PlanetScale, Cloudflare D1, and Vercel Postgres

Common Use Cases

  • Adding a typed data layer to a Next.js, Remix, or SvelteKit app without a code-generation build step
  • Running database access from edge/serverless functions (Cloudflare Workers, Vercel Edge) where lightweight, dependency-free clients matter
  • Migrating off a heavier ORM (Prisma, TypeORM) when teams want SQL-like control with full TypeScript inference
  • Building internal tools or admin panels quickly using Drizzle Studio alongside the schema already defined for the app

Under The Hood

Architecture — drizzle-orm/src/index.ts re-exports the dialect-agnostic core: column/table builders (column-builder.ts, column.ts, table.ts), the branded-type system (entity.ts), and the SQL AST builder (sql/sql.ts, 722 lines). Each dialect (pg-core/, mysql-core/, sqlite-core/, singlestore-core/, gel-core/) implements its own column types and query builders on top of that shared AST — for example pg-core/query-builders/select.ts (1,346 lines) builds a Query object that is rendered through a BuildQueryConfig interface (escapeName/escapeParam/escapeString), which is how one query-builder API targets many SQL dialects. Driver adapters (node-postgres/, postgres-js/, neon-http/, libsql/, better-sqlite3/, bun-sqlite/, d1/, planetscale-serverless/, mysql2/, and more) each wrap one database client and adapt it to a common Session/QueryPromise interface (session.ts, query-promise.ts). Because the library is split across dozens of separately-published driver packages, instanceof checks are unreliable across module boundaries, so the codebase uses a symbol-based entityKind brand and an is() helper (entity.ts) pervasively instead.

Tech Stack — Pure TypeScript, published as dual ESM/CJS via a custom scripts/build.ts. The core drizzle-orm package declares zero runtime dependencies in package.json — all 29 database drivers and clients (pg, mysql2, better-sqlite3, @neondatabase/serverless, @libsql/client, and others) are optional peerDependencies, so consumers only install what they actually use. The repository is a pnpm + Turborepo monorepo (pnpm-workspace.yaml, turbo.json) housing sibling packages drizzle-kit (migrations CLI), drizzle-zod/drizzle-valibot/drizzle-arktype/drizzle-typebox (schema-validation bridges), and drizzle-seed. It targets every major JavaScript runtime — Node.js, Bun, Deno, Cloudflare Workers/D1, Vercel Edge, and React Native via op-sqlite/expo-sqlite adapters.

Code Quality — There are no unit test files co-located in drizzle-orm/src/, but the root-level integration-tests/ workspace contains 68 test files (run via Vitest against real database connections per dialect) plus a separate type-tests/ directory that performs compile-time type assertions to catch inferred query-type regressions — a pattern suited to a library whose main product is precise type inference. Error handling is centralized through a DrizzleError/DrizzleQueryError hierarchy (errors.ts) that preserves the original driver error on .cause. Naming and file layout are strikingly consistent across dialect implementations — pg-core/, mysql-core/, and sqlite-core/ mirror each other’s structure almost exactly, which keeps the cost of adding a new dialect low and the codebase easy to navigate once one dialect is understood.

API Design — A single call, drizzle(client, { schema }), returns a fully-typed db object usable immediately for both SQL-style chained queries (db.select().from(table).where(...)) and relational-style queries (db.query.table.findMany()), with no separate code-generation step — the TypeScript schema declaration is itself the source of type inference. A minimal schema.ts using pgTable(...)/sqliteTable(...) is enough to get full autocomplete on selects, inserts, joins, and relations. The trade-off is setup complexity: the 29-entry peerDependencies list means a new user has to correctly match a driver package to their database and runtime before anything works, and the per-driver README files scattered through src/ (postgres-js/README.md, kysely/README.md, etc.) reflect how much dialect/driver-specific knowledge the API surface still requires.

Used by 118 apps in this directory

TypeScript
96%
Other

LLM Gateway

AI Development · Devops

1,663

One API endpoint for 25+ LLM providers — route, track costs, enforce compliance, and switch models without changing your code.

View details
86
Repo Health
80
Technical
68
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
96%
Other

LLM Gateway

AI Development · Devops

1,663

One API endpoint for 25+ LLM providers — route, track costs, enforce compliance, and switch models without changing your code.

View details
86
Repo Health
80
Technical
68
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
96%
Other

LLM Gateway

AI Development · Devops

1,663

One API endpoint for 25+ LLM providers — route, track costs, enforce compliance, and switch models without changing your code.

View details
86
Repo Health
80
Technical
68
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
99%
Other

LobeHub

AI Assistants · Automation · Productivity

82,864

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
66
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
TypeScript
99%
Other

LobeHub

AI Assistants · Automation · Productivity

82,864

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
66
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
TypeScript
99%
Other

LobeHub

AI Assistants · Automation · Productivity

82,864

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
66
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
TypeScript
99%
AGPL 3.0

Manage

Collaboration · Project Management

71

Self-hosted, open-source project management with tasks, calendars, docs, and real-time team collaboration.

View details
39
Repo Health
57
Technical
71
Dependency
Built with
TypeScript 99%
Updated 2 months ago
TypeScript
99%
AGPL 3.0

Manage

Collaboration · Project Management

71

Self-hosted, open-source project management with tasks, calendars, docs, and real-time team collaboration.

View details
39
Repo Health
57
Technical
71
Dependency
Built with
TypeScript 99%
Updated 2 months ago
TypeScript
99%
Apache 2.0

Mastra Code

AI Code Assistants

28,378

"A coding agent that never compacts" — a terminal-based AI coding agent built on the Mastra framework, with Observational Memory instead of context compaction, multi-model support, and OAuth login for Claude Max or ChatGPT Plus.

View details
90
Repo Health
73
Technical
65
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers