ScriptsApr 6, 2026·2 min read

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.

TL;DR
Drizzle ORM gives you type-safe SQL queries in TypeScript with zero runtime overhead and schema-as-code.
§01

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.

§02

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.

§03

How to use

  1. Install Drizzle:
npm install drizzle-orm postgres
npm install -D drizzle-kit
  1. 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(),
});
  1. 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 }[]
§04

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));
§05

Related on TokRepo

§06

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

How is Drizzle different from Prisma?+

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.

Does Drizzle support serverless environments?+

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.

How do migrations work?+

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.

Can I use raw SQL with Drizzle?+

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.

What databases does Drizzle support?+

Drizzle supports PostgreSQL, MySQL, and SQLite. Driver adapters exist for node-postgres, mysql2, better-sqlite3, Neon, PlanetScale, Turso, and Cloudflare D1.

Citations (3)
🙏

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

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets