Skip to content
Skills Library
Programming · Building & coding

drizzle

/drizzle

Expert Drizzle ORM assistance covering type-safe schema declaration, migrations, relations, and serverless database clients. Use when building performant TypeScript apps with PostgreSQL, MySQL, or SQLite.

Licence
MIT
Last repository change
01.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 01.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Expert Drizzle ORM assistance covering type-safe schema declaration, migrations, relations, and serverless database clients. Use when building performant TypeScript apps with PostgreSQL, MySQL, or SQLite.

Original author description

Expert Drizzle ORM assistance covering type-safe schema declaration, migrations, relations, and serverless database clients. Use when building performant TypeScript apps with PostgreSQL, MySQL, or SQLite.

How it works

  1. When to Use
  2. Quick Start
  3. Core Concepts
  4. Common Patterns
  5. Best Practices
  6. Troubleshooting
  7. References
Original SKILL.md headings · 182 lines, 645 words
SKILL.md preview
---
name: drizzle
description: Expert Drizzle ORM assistance covering type-safe schema declaration, migrations, relations, and serverless database clients. Use when building performant TypeScript apps with PostgreSQL, MySQL, or SQLite.
---

# Drizzle ORM

Drizzle ORM is a lightweight, type-safe TypeScript ORM that mirrors SQL syntax directly, featuring zero runtime overhead, instant cold starts, and seamless edge-runtime support.

## When to Use

- **TypeScript-First Object Relational Mapping**: Lightweight, SQL-like ORM with zero code-generation overhead and maximum type safety.
- **Serverless & Edge Runtimes**: Next.js, Cloudflare Workers, Bun, Supabase, and AWS Lambda with zero cold-start penalty.
- **Relational Databases with Precise Control**: PostgreSQL, MySQL, and SQLite requiring explicit query execution and predictable SQL output.
- **Schema-as-Code & Declarative Migrations**: Managing migrations cleanly with `drizzle-kit`.

## Quick Start

```typescript
// schema.ts
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(),
});

// query.ts
import { drizzle } from "drizzle-orm/node-postgres";
import { users } from "./schema";

const db = drizzle(process.env.DATABASE_URL);
const allUsers = await db.select().from(users);
```

## Core Concepts

### Declarative Schema Definition with Relationships

Type-safe table schemas and foreign key relations:

```typescript
import {
  pgTable,
  serial,
  text,
  timestamp,
  integer,
  boolean,
} from "drizzle-orm/pg-core";
import { relations } from "drizzle-orm";

export const users = pgTable("users", {
  id: serial("id").primaryKey(),
  email: text("email").notNull().unique(),
  fullName: text("full_name").notNull(),
  createdAt: timestamp("created_at").defaultNow().notNull(),
});

export const posts = pgTable("posts", {
  id: serial("id").primaryKey(),
  title: text("title").notNull(),
  authorId: integer("author_id")
    .notNull()
    .references(() => users.id, { onDelete: "cascade" }),
  published: boolean("published").default(false).notNull(),
});

export const usersRelations = relations(users, ({ many }) => ({
  posts: many(posts),
}));

export const postsRelations = relations(posts, ({ one }) => ({
  author: one(users, {
    fields: [posts.authorId],
    references: [users.id],
  }),
}));
```

### Relational Queries & SQL-Like Filtering

Intuitive query API combining SQL syntax with relational loading:

```typescript
import { drizzle } from "drizzle-orm/node-postgres";
import { eq, desc, and } from "drizzle-orm";
import { users, posts } from "./schema";

const db = drizzle(process.env.DATABASE_URL!);

// Relational query mode
async function getAuthorWithPosts(userId: number) {
  return await db.query.users.findFirst({
    where: eq(users.id, userId),
    with: {
      posts: {
        where: eq(posts.published, true),
        orderBy: [desc(posts.id)],
      },
    },
  });
}

// SQL-like query builder mode
async function updatePostStatus(postId: number, isPublished: boolean) {
  return await db
    .update(posts)
    .set({ published: isPublished })
    .where(eq(posts.id, postId))
    .returning();
}
```

### Drizzle Kit Migrations & Introspection

Declarative migration generation and application:

```typescript
// drizzle.config.ts
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  schema: "./src/db/schema.ts",
  out: "./drizzle",
  dialect: "postgresql",
  dbCredentials: {
    url: process.env.DATABASE_URL!,
  },
  verbose: true,
  strict: true,
});
```

## Common Patterns

### Relational Queries with Prepared Statements

**Problem**: Writing complex SQL joins while retaining strict compile-time TypeScript type inference.

**Solution**:
Use Drizzle's Relational Queries API:

```typescript
import { eq } from "drizzle-orm";

const userWithPosts = await db.query.users.findFirst({
  where: eq(users.id, 1),
  with: {
    posts: {
      columns: { title: true, createdAt: true },
      limit: 5,
    },
  },
});
```

## Best Practices

**Do**:

- Split schemas into modular domain files and export them through a centralized `schema.ts`.
- Use `db.query` for nested relational reads and standard SQL query builder for mutations and bulk operations.
- Run `drizzle-kit check` and `drizzle-kit generate` in CI to detect schema discrepancies before deployment.
- Specify `onDelete` cascades explicitly on all foreign key constraints.

**Don't**:

- Perform multiple round-trips for insert-then-read; use `.returning()` to fetch modified rows immediately.
- Instantiate multiple database client connections in serverless edge handlers; reuse client instances.
- Mix multiple SQL dialects in a single schema definition.

## Troubleshooting

| Error                                                     | Cause                                                              | Solution                                                               |
| :-------------------------------------------------------- | :----------------------------------------------------------------- | :--------------------------------------------------------------------- |
| `Error: relation "..." does not exist`                    | Migrations have not been generated or pushed to database.          | Run `npx drizzle-kit generate` and `npx drizzle-kit migrate`.          |
| `Type error: Property 'query' does not exist on type ...` | Schema not passed to `drizzle(client, { schema })` initialization. | Pass your schema object: `drizzle(client, { schema: { ...schema } })`. |
| `duplicate key value violates unique constraint`          | Inserting record with existing unique column value.                | Use `.onConflictDoNothing()` or `.onConflictDoUpdate()`.               |

## References

- [Drizzle ORM Documentation](https://orm.drizzle.team/)

Versions

RepositoryScoreLicence
This page · G1Joshi/Agent-Skills100MIT
triggerdotdev/trigger.dev100Apache-2.0
claude-dev-suite/claude-dev-suite100MIT
Esposter/Esposter90Apache-2.0

Database snapshot: 13.11.2026 · package version c85fec9516c1 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 85Drizzle ORM
    Expert guidance for Drizzle ORM including schema definition, queries, relations, migrations, TypeScript integration with SQLite/PostgreSQL, and Drizzle Studio. Use this when working with type-safe database operations, schema management, or ORM queries.
  • 100drizzle-orm-expert
    Expert in Drizzle ORM for TypeScript — schema design, relational queries, migrations, and serverless database integration. Use when building type-safe database layers with Drizzle.
  • 100drizzle-orm-expert
    Expert in Drizzle ORM for TypeScript — schema design, relational queries, migrations, and serverless database integration. Use when building type-safe database layers with Drizzle.
  • 100drizzle-orm-patterns
    Provides comprehensive Drizzle ORM patterns for schema definition, CRUD operations, relations, queries, transactions, and migrations. Proactively use for any Drizzle ORM development including defining database schemas, writing type-safe queries, implementing relations, managing…
  • 100drizzle-orm-expert
    Provides Drizzle ORM schema design, query patterns, migrations, and TypeScript integration for SQL databases. Use when working with Drizzle files (schema.ts, drizzle.config.ts) or when the user mentions Drizzle ORM or drizzle-kit.
  • 100drizzle-orm-d1
    | Type-safe ORM for Cloudflare D1 databases using Drizzle. Use when: building D1 database schemas, writing type-safe SQL queries, managing migrations with Drizzle Kit, defining table relations, implementing prepared statements, using D1 batch API, or encountering D1_ERROR,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.