TypeScript ORM for SQL databases with type-safe queries, schema definitions, and support for PostgreSQL, MySQL, SQLite, and more.
npx @tessl/cli install tessl/npm-drizzle-orm@0.45.0Lightweight, headless TypeScript ORM for SQL databases providing a thin typed layer on top of SQL. Supports PostgreSQL, MySQL, SQLite, SingleStore, and GEL with zero runtime dependencies.
import { drizzle } from 'drizzle-orm/node-postgres';
import { pgTable, serial, text, varchar } from 'drizzle-orm/pg-core';
import { eq } from 'drizzle-orm';
import { Pool } from 'pg';
// Define schema
const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
email: varchar('email', { length: 255 }).notNull().unique(),
});
// Initialize database
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const db = drizzle(pool);
// Query data
const allUsers = await db.select().from(users);
const user = await db.select().from(users).where(eq(users.id, 1));
// Insert data
await db.insert(users).values({ name: 'John', email: 'john@example.com' });
// Update data
await db.update(users).set({ name: 'Jane' }).where(eq(users.id, 1));
// Delete data
await db.delete(users).where(eq(users.id, 1));npm install drizzle-ormFor specific drivers:
npm install drizzle-orm pg # PostgreSQL (node-postgres)
npm install drizzle-orm postgres # PostgreSQL (postgres-js)
npm install drizzle-orm mysql2 # MySQL
npm install drizzle-orm better-sqlite3 # SQLiteimport { drizzle } from 'drizzle-orm/[driver]';
import { pgTable, serial, text, varchar } from 'drizzle-orm/pg-core';
import { eq, and, or, sql } from 'drizzle-orm';Replace [driver] with: node-postgres, postgres-js, mysql2, better-sqlite3, libsql, neon-serverless, etc.
type InferSelectModel<TTable> = // Infer SELECT result type
type InferInsertModel<TTable> = // Infer INSERT input type
// Also available as properties:
table.$inferSelect // Type of SELECT result
table.$inferInsert // Type of INSERT inputinterface DrizzleConfig<TSchema> {
logger?: Logger | boolean;
schema?: TSchema;
casing?: 'snake_case' | 'camelCase';
cache?: Cache;
}| Database | Drivers | Key Features |
|---|---|---|
| PostgreSQL | pg, postgres-js, Neon, Vercel, AWS RDS, PGlite, Xata, Supabase | JSONB, arrays, enums, PostGIS, pgvector, RLS, materialized views |
| MySQL | mysql2, PlanetScale, TiDB | JSON, full-text indexes, spatial indexes |
| SQLite | better-sqlite3, Bun, libSQL/Turso, D1, Expo, OP SQLite, sql.js | JSON mode, RETURNING, embedded/serverless |
| SingleStore | native driver | MySQL-compatible with optimizations |
| GEL | native driver | EdgeDB-like features |
class DrizzleError extends Error {}
class DrizzleQueryError extends DrizzleError {}
class TransactionRollbackError extends DrizzleError {}