drizzle
Skill15 starsChanged 43 days agoMITView on GitHub
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.
- Reads credentials
6 other projects use a version of this.
Adopted by
Most recently taken up by
- lobehub/lobehubtheir own version, first seen Nov 5, 2026
- tazo90/next-openapi-gentheir own version, first seen Oct 8, 2026
- lobehub/lobe-chattheir own version, first seen Oct 8, 2026
- triggerdotdev/trigger.devtheir own version, first seen Aug 12, 2026
- miketromba/skillstheir own version, first seen Apr 8, 2026
- leonaaardob/lb-drizzle-skilltheir own version, first seen Feb 7, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- lobehub/lobe-chat★ 84ksame name
- lobehub/lobehub★ 84ksame name
- triggerdotdev/trigger.dev★ 17ksame name
- tazo90/next-openapi-gen★ 196same name
- miketromba/skills★ 2same name
- leonaaardob/lb-drizzle-skill★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- xgboostSkill
- api-gatewaySkill
- clean-architectureSkill
- cqrsSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- hexagonalSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- sagaSkill
- serverlessSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. 0 are common, 1 is distinctive, and 2 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 144
Use Drizzle's Relational Queries API:
- Very specific: line 165
Use db.query for nested relational reads and standard SQL query builder for mutations and bulk operations.
- Very specific: line 166
Run drizzle-kit check and drizzle-kit generate in CI to detect schema discrepancies before deployment.
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
// 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:
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:
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:
// 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:
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.queryfor nested relational reads and standard SQL query builder for mutations and bulk operations. - Run
drizzle-kit checkanddrizzle-kit generatein CI to detect schema discrepancies before deployment. - Specify
onDeletecascades 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
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

