Drizzle ORM is a TypeScript ORM that keeps SQL visible: you declare tables in TypeScript, write queries that read like SQL, and get result types inferred from the schema.[1] Choose it when you already know SQL, deploy to serverless or edge runtimes, and want migrations generated from your code. It has zero dependencies and supports PostgreSQL, MySQL, SQLite, SingleStore, MSSQL and CockroachDB.[1] One version catch up front: npm latest is 0.45.4, while the current docs install drizzle-orm@rc and GitHub's newest release is v1.0.0-rc.6 from November 20, 2026.[12][13][2] This guide follows the rc docs.
What Drizzle ORM is, and when to choose it
Drizzle describes itself as a headless ORM: a library plus opt-in tools, not a framework you build around.[1] Two query styles ship in the same package. The SQL-like builder (db.select().from(...)) mirrors SQL clause by clause. The relational API (db.query) fetches nested data without hand-written joins, and Drizzle's docs say it always emits exactly one SQL query.[1] The docs call it the only ORM with both styles. That is a vendor claim, not something this guide checked.
Pick it if:
Your team reads SQL fluently and wants the query code to look like the SQL it produces.
You deploy to serverless or edge, where a dependency-free library keeps the bundle small.[1]
You want the TypeScript schema to be the source of truth, with migration files generated from it.[7]
You are fine running on a pre-release line today (see the version section below).
Skip it if your team wants a query API that hides SQL entirely. The docs say plainly that if you know SQL you know Drizzle, which also means you need to know SQL.[1] For a refresher on the joins you will write, see SQL join types explained.
Which version to install: stable 0.45.4 or the v1 rc
The npm page lists drizzle-orm 0.45.4 as the current version, published about two months before this guide's access date.[13] The GitHub releases page lists v1.0.0-rc.6, marked pre-release, published November 20, 2026.[12] The docs site's install commands use the @rc tag for both packages.[2] The docs site banner still links the v1.0.0-beta.2 release, so older tutorials may mention a beta tag that is no longer the newest.
That split matters because the APIs differ. The rc docs use Relational Queries v2 (defineRelations). The 0.x line uses the older relations() function with per-table objects. Drizzle's migration guide says RQB v1 support has been removed from the database drivers in the rc line, and that getTableColumns is deprecated in v1 in favor of getColumns.[6][4] Every snippet below follows the rc docs. If you pin 0.45.x, expect the relations code to differ, and check the 0.x docs before copying.
Drizzle ORM setup with PostgreSQL
Drizzle supports the node-postgres and postgres.js drivers natively. The docs' node-postgres install and first query look like this:[2]
npm i drizzle-orm@rc pg
npm i -D drizzle-kit@rc @types/pg
// Make sure to install the 'pg' package
import { drizzle } from 'drizzle-orm/node-postgres';
const db = drizzle(process.env.DATABASE_URL);
const result = await db.execute('select 1');
One driver difference from the docs: postgres.js uses prepared statements by default, which you may need to opt out of, for example in some AWS environments.[2] The docs list a roughly 10% speed boost from installing pg-native with node-postgres.[2]
Declare a schema in TypeScript
A table is a TypeScript object built with the dialect's table function. This example comes from the schema docs, and the same page shows a callback form and an import * as p form.[3]
import { integer, pgTable, varchar } from "drizzle-orm/pg-core";
export const usersTable = pgTable("users", {
id: integer().primaryKey().generatedAlwaysAsIdentity(),
name: varchar().notNull(),
age: integer().notNull(),
email: varchar().notNull().unique(),
});
By default Drizzle uses the TypeScript key as the column name. To keep camelCase in code and snake_case in the database, either pass an alias such as varchar('first_name') or use the snakeCase.table(...) builder from drizzle-orm/pg-core.[3] The schema can live in one file or many. If you use drizzle-kit, export every model so the migration diff can see it, and point the schema option at the file, folder or glob.[3]
Query data: SQL-like select, insert and relational queries
The snippets below follow the docs' query examples and assume a users table with a serial id, a name and a nullable age, not the usersTable from the schema example above.[4] The SQL-like API lists columns explicitly instead of using select *, infers the result type from the table (including nullability) and parameterizes every value passed to filters.[4] Inserts use .values() and, on PostgreSQL, .returning().[11]
import { eq, and } from 'drizzle-orm';
// select with a filter
await db.select().from(users).where(
and(eq(users.id, 42), eq(users.name, 'Dan'))
);
// partial select
await db.select({ field1: users.id, field2: users.name }).from(users);
// insert and get the row back
await db.insert(users).values({ name: "Dan" }).returning();
// upsert
await db.insert(users)
.values({ id: 1, name: 'Dan' })
.onConflictDoUpdate({ target: users.id, set: { name: 'John' } });
The relational API needs relations defined once with defineRelations and passed to drizzle(). This is the rc docs shape (RQB v2), and it assumes a posts table with an authorId column in the same schema file:[5]
// relations.ts
import { defineRelations } from "drizzle-orm";
import { posts, users } from "./schema";
export const relations = defineRelations({ users, posts }, (r) => ({
posts: {
author: r.one.users({
from: r.posts.authorId,
to: r.users.id,
}),
},
users: {
posts: r.many.posts(),
},
}));
// index.ts
import { relations } from "./relations";
import { drizzle } from "drizzle-orm/node-postgres";
const db = drizzle(process.env.DATABASE_URL, { relations });
const result = await db.query.users.findMany({
with: { posts: true },
});
Filters in the relational API are objects, not function calls. The docs list operators such as eq, gt, like, in, isNull and the combinators OR, AND, NOT and RAW. For example, where: { id: 1 } filters on a column, and nested with blocks can carry their own where.[5]
drizzle-kit command reference
drizzle-kit is the CLI companion. It supports a database-first flow (pull), a codebase-first flow with no SQL files (push), and a codebase-first flow with SQL files (generate, then migrate).[7] Dialect and schema path go in drizzle.config.ts via defineConfig.[8]
| Command | What it does | Options the docs list |
|---|
| drizzle-kit generate | Diffs the current schema against previous migrations and writes migration.sql plus snapshot.json in a timestamped folder[8] | --name, --custom (empty SQL file), --ignore-conflicts, --config[8] |
| drizzle-kit migrate | Applies unapplied SQL migrations and logs them in __drizzle_migrations in the drizzle schema[10] | migrations.table and migrations.schema in config[10] |
| drizzle-kit push | Introspects the database, diffs it against your schema and applies the changes directly, with no SQL files[9] | --verbose, --explain (dry run), --force (auto-accept data-loss statements)[9] |
| drizzle-kit pull | Reads an existing database and writes a TypeScript schema file[7] | See the pull docs |
| drizzle-kit export | Prints SQL for your schema to the console, for tools such as Atlas[7] | See the export docs |
A minimal config and the generate-then-migrate loop, following the docs:[8][10]
// drizzle.config.ts
import { defineConfig } from "drizzle-kit";
export default defineConfig({
dialect: "postgresql",
schema: "./src/schema.ts",
dbCredentials: {
url: "postgresql://user:password@host:port/dbname",
},
});
npx drizzle-kit generate --name=init
npx drizzle-kit migrate
The docs describe push as the best approach for rapid prototyping and say they have seen dozens of teams and solo developers use it as their primary migrations flow in production.[9] If you want reviewable SQL in version control, use generate and migrate instead. You can also run generated migrations at application start with the migrate() function from the driver's migrator module.[7]
Drizzle vs Prisma
Both projects are in transition, which changes the comparison. Prisma's docs now default to Prisma ORM 8, a release candidate that npm install prisma installs today. Prisma ORM 7 docs stay at /orm/v7, and Prisma says Prisma ORM 7 stays supported for 18 months after release 8.0.[14][15] The table compares the Drizzle rc docs with the Prisma ORM 8 docs, and notes where Prisma ORM 7 differs.
| Area | Drizzle ORM (rc docs) | Prisma ORM 8 (rc docs) |
|---|
| Where the schema lives | TypeScript files using pgTable and friends[3] | A contract file, contract.prisma, with models; it replaces schema.prisma from Prisma ORM 7[14] |
| Query style | SQL-like builder, plus a relational db.query API[1] | Model methods such as db.orm.public.User.include("posts").all()[14] |
| Result types | Inferred from the table definitions[4] | Typed from the contract after npx prisma contract emit, which replaces prisma generate[14] |
| Migrations | drizzle-kit generate then migrate, or push[7] | npx prisma migration plan writes a migration to review; npx prisma db migrate applies it[14] |
| Client package | drizzle-orm with a driver such as pg[2] | A per-database library, @prisma/orm-postgres; no @prisma/client[15] |
| Release state, December 5, 2026 | v1.0.0-rc.6 pre-release; npm latest 0.45.4[12][13] | Release candidate; prisma 8.0.0-rc.39 and @prisma/orm-postgres 8.0.0-rc.28 per Prisma's page dated December 3[15] |
| Databases | PostgreSQL, MySQL, SQLite, SingleStore, MSSQL, CockroachDB[1] | PostgreSQL is GA from 8.0; MongoDB, SQLite, MySQL, MariaDB are Early Access; SQL Server and CockroachDB come later[14] |
Prisma's contract looks like this in its docs:[14]
// use prisma-8
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
author User @relation(fields: [authorId], references: [id])
authorId Int
}
The practical difference is where you describe your data. Drizzle keeps it in TypeScript, so a table definition is also a value you can spread, share and import. Prisma keeps it in its own modeling language and gives you typed methods from it. Neither project's docs include a benchmark this guide could verify, so there are no speed claims here. Drizzle links a benchmarks page from its docs header, and anything on it is vendor-reported.
If you need a stable release on a database Prisma ORM 8 does not yet cover well, Prisma's own page says to stay on Prisma ORM 7 for MySQL, MariaDB, SQL Server and CockroachDB.[14] If you are starting a PostgreSQL project and want SQL-shaped code, Drizzle on the rc tag is the closer fit. Pin the exact version either way, since Prisma notes that no compatibility between release candidates is promised.[15]
Common Drizzle mistakes and what breaks
| Mistake | What happens | Fix |
|---|
| Installing without @rc but copying rc docs | You get 0.45.4, and defineRelations code may not match that line[13][6] | Install drizzle-orm@rc and drizzle-kit@rc, or pin 0.x and use the 0.x docs |
| Not exporting a table from a schema file | drizzle-kit cannot see it in the migration diff[3] | Export every model |
| Forgetting { relations } in drizzle() | db.query has nothing to resolve[5] | Pass the relations object at initialization |
| Referencing the imported table inside relational orderBy, where.RAW or extras | Docs mark it as wrong; the callback parameter supplies the aliased table for correct SQL[5] | Use the callback: orderBy: (t) => ... |
| Writing sql<number> for a value the driver returns as a string | Types and runtime values disagree; Drizzle cannot cast from the generic[4] | Match the generic to the real type or use .mapWith() |
| Running push --force against production | Data-loss statements are accepted automatically[9] | Run push --explain first, or switch to generate and migrate |
| Relying on a driver's custom type parsers after rc.6 | The rc.6 notes say drivers no longer configure output decoding, and custom parsers need custom codecs[12] | Read the rc.6 release notes before upgrading |
A last habit worth keeping: read the generated migration.sql before it runs. When you want to inspect or tidy hand-written SQL for a custom migration, the SQL formatter helps. If a column is a timestamp, decide on time zone handling at schema time. The PostgreSQL timestamp vs timestamptz guide covers the rule and the bugs.
Sources
Why Drizzle?, Drizzle ORM documentation (accessed December 5, 2026)
Drizzle <> PostgreSQL, Drizzle ORM documentation (accessed December 5, 2026)
Drizzle schema, Drizzle ORM documentation (accessed December 5, 2026)
SQL Select, Drizzle ORM documentation (accessed December 5, 2026)
Drizzle Queries (relational queries), Drizzle ORM documentation (accessed December 5, 2026)
Migrating to Relational Queries version 2, Drizzle ORM documentation (accessed December 5, 2026)
Drizzle migrations fundamentals, Drizzle ORM documentation (accessed December 5, 2026)
drizzle-kit generate, Drizzle ORM documentation (accessed December 5, 2026)
drizzle-kit push, Drizzle ORM documentation (accessed December 5, 2026)
drizzle-kit migrate, Drizzle ORM documentation (accessed December 5, 2026)
SQL Insert, Drizzle ORM documentation (accessed December 5, 2026)
Releases, drizzle-team/drizzle-orm, GitHub (accessed December 5, 2026)
What is Prisma ORM?, Prisma Documentation (accessed December 5, 2026)
15. Prisma ORM release status, Prisma Documentation (accessed December 5, 2026)
Originally published at wowhow.cloud
Top comments (0)