What it does
Drizzle ORM provides typed schemas and query builders for SQL databases. Its companion Drizzle Kit supports schema-driven migration workflows.
Why it’s interesting
Queries remain close to SQL, making generated statements easier to inspect. Type inference improves editor feedback, but query plans, indexes, and N+1 behavior still require developer attention.
Real-world use case
Use a shared schema in a Next.js backend to query PostgreSQL and keep SQL migration files under version control.
What I can learn
- 01
Query compilation
turn expressions into parameterized SQL.
- 02
Type mapping
infer selected columns and joined result shapes.
- 03
Driver adapters
support different SQL engines and connection transports.
One thing to explore
SQL expression construction
Follow the implementation and connect it to the learning points above.
Explore the source (opens in a new tab)10-Minute Challenge
Query an in-memory SQLite database
Before you start: Node.js and npm; better-sqlite3 may require native build tooling.
- Install the dependencies below.
- Save the TypeScript example as demo.ts.
- Run npx tsx demo.ts, then select only the name column and inspect the inferred result type.
npm install drizzle-orm better-sqlite3npm install -D tsx @types/better-sqlite3import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';import { drizzle } from 'drizzle-orm/better-sqlite3';import Database from 'better-sqlite3';
const users = sqliteTable('users', { id: integer('id').primaryKey({ autoIncrement: true }), name: text('name').notNull(), email: text('email').notNull().unique(),});const sqlite = new Database(':memory:');const db = drizzle(sqlite);sqlite.exec('CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE)');db.insert(users).values({ name: 'Nikhil Anand', email: 'nikhil@example.com' }).run();console.log(db.select().from(users).all());