Drizzle ORM — TypeScript SQL That Feels Like Code
Type-safe TypeScript ORM with SQL-like syntax. Zero overhead, serverless-ready, supports PostgreSQL, MySQL, SQLite. Schema as code with automatic migrations. 28,000+ GitHub stars.
What it is
Drizzle ORM is a TypeScript ORM that mirrors SQL syntax directly in your code. Instead of learning a new query API, you write queries that look like SQL but with full TypeScript type safety. It supports PostgreSQL, MySQL, and SQLite with zero runtime overhead, meaning the generated SQL is exactly what you would write by hand.
Drizzle targets TypeScript developers building serverless functions, edge workers, and full-stack applications who want type safety without the performance cost of traditional ORMs.
How it saves time or tokens
Drizzle eliminates the gap between your mental model of SQL and your ORM code. If you know SQL, you know Drizzle. Schema-as-code means your database schema lives in TypeScript files, version-controlled alongside your application. Drizzle Kit handles migrations automatically by diffing your schema against the database. The zero-overhead design means queries compile to plain SQL with no runtime parsing or transformation.
How to use
- Install Drizzle:
npm install drizzle-orm postgres
npm install -D drizzle-kit
- Define your schema:
import { pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core';
export const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
email: text('email').notNull().unique(),
createdAt: timestamp('created_at').defaultNow(),
});
- Query with full type safety:
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import { users } from './schema';
import { eq } from 'drizzle-orm';
const client = postgres(process.env.DATABASE_URL!);
const db = drizzle(client);
const result = await db.select().from(users).where(eq(users.email, 'alice@example.com'));
// result is typed as { id: number; name: string; email: string; createdAt: Date }[]
Example
Joins and relations with type inference:
import { pgTable, serial, text, integer } from 'drizzle-orm/pg-core';
export const posts = pgTable('posts', {
id: serial('id').primaryKey(),
title: text('title').notNull(),
authorId: integer('author_id').references(() => users.id),
});
const postsWithAuthors = await db
.select({ title: posts.title, author: users.name })
.from(posts)
.innerJoin(users, eq(posts.authorId, users.id));
Related on TokRepo
- Database tools — AI-assisted database utilities and ORMs
- AI coding tools — development tools and frameworks
Common pitfalls
- Drizzle's SQL-like API means you need to know SQL. Developers expecting a high-level abstraction like ActiveRecord may find it verbose for simple CRUD.
- Migration files generated by Drizzle Kit should be reviewed before running in production. Automatic diffing can produce unexpected ALTER TABLE statements.
- The ecosystem of plugins and extensions is smaller than Prisma's. Check community adapter availability for your specific database driver.
Frequently Asked Questions
Prisma uses its own schema language (Prisma Schema) and generates a client with a custom query API. Drizzle uses TypeScript for schemas and mirrors SQL syntax directly. Drizzle has zero runtime overhead while Prisma includes a query engine binary.
Yes. Drizzle works with serverless databases like Neon, PlanetScale, Turso, and Cloudflare D1. Its zero-dependency design and small bundle size make it ideal for edge and serverless runtimes.
Drizzle Kit compares your TypeScript schema against the database and generates SQL migration files. Run drizzle-kit generate to create migrations and drizzle-kit migrate to apply them.
Yes. Drizzle provides a sql template tag for raw SQL queries while maintaining type safety. You can also use db.execute() for fully custom queries.
Drizzle supports PostgreSQL, MySQL, and SQLite. Driver adapters exist for node-postgres, mysql2, better-sqlite3, Neon, PlanetScale, Turso, and Cloudflare D1.
Citations (3)
- Drizzle ORM GitHub— Drizzle ORM provides type-safe SQL with zero runtime overhead
- Drizzle Documentation— Schema-as-code with automatic migration generation via Drizzle Kit
- Drizzle Drivers— Supports PostgreSQL, MySQL, SQLite with multiple driver adapters
Related on TokRepo
Source & Thanks
Created by Drizzle Team. Licensed under Apache 2.0.
drizzle-orm — ⭐ 28,000+
Thanks for making TypeScript and SQL feel like the same language.
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.