| name | drizzle |
| description | Drizzle ORM type-safe queries, schema definitions, migrations, relations, transactions, and performance patterns |
| layer | domain |
| category | database |
| triggers | ["drizzle","drizzle orm","drizzle kit","drizzle schema","drizzle query"] |
| inputs | ["Data model requirements","Query patterns","Migration needs"] |
| outputs | ["Drizzle schema definitions","Type-safe query implementations","Migration configurations"] |
| linksTo | ["postgresql","nodejs","graphql","microservices"] |
| linkedFrom | ["error-handling","testing"] |
| preferredNextSkills | ["postgresql","nodejs","redis"] |
| fallbackSkills | ["prisma","supabase"] |
| riskLevel | low |
| memoryReadPolicy | selective |
| memoryWritePolicy | none |
| sideEffects | [] |
Drizzle ORM Domain Skill
Purpose
Provide expert-level guidance on Drizzle ORM, including schema definitions, type-safe queries, relational queries, migrations with Drizzle Kit, transactions, prepared statements, and performance optimization. Drizzle is SQL-first: if you know SQL, you know Drizzle.
Why Drizzle
- Zero overhead: Generates SQL at build time, no runtime query parsing
- SQL-like API:
select().from().where() maps directly to SQL
- Full type safety: Schema types flow through all queries
- Serverless-friendly: Lightweight, no heavy runtime, works with edge functions
- Relational queries: Prisma-like
with syntax for nested data
Key Patterns
1. Schema Definition
import {
pgTable, text, timestamp, boolean, integer, uuid,
uniqueIndex, index, pgEnum, check, primaryKey,
} from 'drizzle-orm/pg-core';
import { relations, sql } from 'drizzle-orm';
export const roleEnum = pgEnum('role', ['admin', 'member', 'viewer']);
export const users = pgTable('users', {
id: uuid('id').primaryKey().defaultRandom(),
email: text('email').notNull(),
name: text('name').(),
: ().().(),
: ().().(),
: ().().(),
: (, { : }).().(),
: (, { : }).().()
.$onUpdate( ()),
: (, { : }),
}, [
().(table.),
().(table., table.),
().(table.).(
sql
),
(, sql),
]);
posts = (, {
: ().().(),
: ().(),
: ().().(),
: ().(),
: ().().(),
: (, { : }),
: ().().( users., { : }),
: ().().(),
: ().(),
: (, { : }).().(),
: (, { : }).().()
.$onUpdate( ()),
}, [
().(table., table.),
().(table., table.),
]);
categories = (, {
: ().().(),
: ().().(),
: ().().(),
});
postsToCategories = (, {
: ().().( posts., { : }),
: ().().( categories., { : }),
: (, { : }).().(),
}, [
({ : [table., table.] }),
]);
usersRelations = (users, ({
: (posts),
: (profiles, {
: [users.],
: [profiles.],
}),
}));
postsRelations = (posts, ({
: (users, {
: [posts.],
: [users.],
}),
: (postsToCategories),
}));
postsToCategoriesRelations = (postsToCategories, ({
: (posts, {
: [postsToCategories.],
: [posts.],
}),
: (categories, {
: [postsToCategories.],
: [categories.],
}),
}));