← marketplace
engineerslibrarysha:8e0d5963a3632cfemanual

drizzle-orm

Use when you want a typesafe SQL-like TypeScript ORM with schema-in-code, zero codegen at runtime, and SQL-driver-agnostic queries.

Install confidence
curl --create-dirs -fsSL https://skillmake.xyz/i/drizzle-orm -o ~/.claude/skills/drizzle-orm/SKILL.md
Pinned content
sha:8e0d5963a3632cfe
Generated with
manual
Source
orm.drizzle.team

The file served at /api/marketplace/drizzle-orm-8e0d5963/raw matches this hash. Inspect before install, then copy the command.

5,222 chars · ~1,306 tokens
---
name: drizzle-orm
description: Use when you want a typesafe SQL-like TypeScript ORM with schema-in-code, zero codegen at runtime, and SQL-driver-agnostic queries.
source: https://orm.drizzle.team/docs/overview
generated: 2026-07-02T18:41:43.545Z
category: library
audience: engineers
---

## When to use

- Building TypeScript apps needing end-to-end inferred types from a SQL schema
- Wanting a thin SQL-flavored query builder rather than a heavy active-record ORM
- Managing schema migrations with drizzle-kit against Postgres, MySQL, or SQLite
- Running on serverless/edge runtimes where a lightweight driver matters

## Key concepts

### Schema in TypeScript

Tables are declared with pgTable/mysqlTable/sqliteTable and column helpers. The schema is plain TS, so types are inferred directly; no separate schema language or runtime codegen.

### drizzle() instance

You create a db client by passing a driver connection (and optionally the schema) to drizzle(). The dialect-specific import (drizzle-orm/node-postgres, /mysql2, /better-sqlite3, etc.) selects behavior.

### Query builder vs Relational Queries

Two APIs: the SQL-like builder (db.select().from().where()) mirrors SQL, while the Relational Queries API (db.query.users.findMany({ with: { posts: true } })) fetches nested relations declaratively.

### drizzle-kit

The CLI for migrations. generate diffs the schema to SQL files, migrate applies them, and push syncs the schema directly to the DB for prototyping.

### Operators and sql template

Conditions use imported operators (eq, and, or, gt, inArray, like). The sql`` template tag escapes parameters and lets you drop to raw SQL safely.

### Type inference

table.$inferSelect and table.$inferInsert (or InferSelectModel/InferInsertModel) derive row and insert types from the schema, keeping app types in sync automatically.

## API reference

```
drizzle(client, { schema })
```

Create the typed database instance from a driver connection and optional schema for relational queries.

```
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';
import * as schema from './schema';

const pool = new Pool({ connectionString: process.env.DATABASE_URL });
export const db = drizzle(pool, { schema });
```

```
pgTable(name, columns)
```

Define a Postgres table; column builders like serial, text, integer, timestamp set types and constraints.

```
import { pgTable, serial, text, integer } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
  age: integer('age'),
});
```

```
db.select().from(table).where(cond)
```

SQL-style read query; chain orderBy, limit, leftJoin, etc.

```
import { eq, and } from 'drizzle-orm';
const rows = await db.select().from(users).where(and(eq(users.name, 'Ada'))).limit(10);
```

```
db.insert(table).values(data).returning()
```

Insert one or many rows; returning() returns inserted columns (Postgres/SQLite).

```
const [row] = await db.insert(users).values({ name: 'Ada', age: 36 }).returning();
```

```
db.update(table).set(data).where(cond)
```

Update matching rows with new values.

```
await db.update(users).set({ age: 37 }).where(eq(users.id, 1));
```

```
db.delete(table).where(cond)
```

Delete matching rows.

```
await db.delete(users).where(eq(users.id, 1));
```

```
db.query.users.findMany({ with })
```

Relational Queries API to fetch rows with nested relations in one call.

```
const data = await db.query.users.findMany({
  where: (u, { eq }) => eq(u.active, true),
  with: { posts: true },
});
```

```
defineConfig({ schema, out, dialect, dbCredentials })
```

drizzle.config.ts used by drizzle-kit to locate schema and target the database.

```
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
  schema: './src/schema.ts',
  out: './drizzle',
  dialect: 'postgresql',
  dbCredentials: { url: process.env.DATABASE_URL! },
});
```

```
drizzle-kit generate | migrate | push | studio
```

CLI: generate SQL migrations, apply them, push schema directly, or open Drizzle Studio.

```
npx drizzle-kit generate
npx drizzle-kit migrate
npx drizzle-kit push
```

## Gotchas

- drizzle-kit push is for prototyping; it can drop data on destructive diffs, so use generate+migrate in production.
- You must pass { schema } to drizzle() to use the db.query relational API; otherwise db.query is undefined.
- Dialect imports differ (pg-core vs mysql-core vs sqlite-core); mixing column helpers across dialects fails.
- returning() is unsupported by MySQL; use insertId or a follow-up select there.
- Relations must be declared with the relations() helper for the relational queries API to resolve with: joins.
- Connection pooling on serverless can exhaust DB connections; use a serverless-aware driver (neon-http, postgres.js) or a pooler.
- Order of operators matters: where() takes one expression, so combine with and()/or() rather than chaining where().
- Migrations run in the order of generated files; editing applied migration SQL by hand can desync the journal.

---
Generated by SkillMake from https://orm.drizzle.team/docs/overview on 2026-07-02T18:41:43.545Z.
Verify against source before relying on details.

File: ~/.claude/skills/drizzle-orm/SKILL.md