drizzle-orm
Drizzle ORM is a lightweight, type-safe TypeScript ORM that treats SQL as a first-class citizen. This skill covers schema definition, database connections across PostgreSQL, SQLite, and Turso, relational queries, and performance patterns like proper indexing and pagination.
Drizzle ORM teaches type-safe TypeScript database development with SQL-like syntax and schema-as-code patterns.
AI-generated summary based on this skill's SKILL.md
Install
Mindrally/skills/drizzle-orm
git clone https://github.com/Mindrally/skills
cp -r skills/drizzle-orm ~/.claude/skills/drizzle-ormFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What is Drizzle ORM and how do I use it?
Drizzle ORM is a lightweight, type-safe TypeScript ORM that treats SQL as a first-class citizen. It provides schema definition, database connections across PostgreSQL, SQLite, and Turso, relational queries, and performance patterns like proper indexing and pagination. Drizzle emphasizes developer experience by keeping you close to SQL while adding type safety and preventing common errors.
How do I define a schema and set up type-safe database queries with Drizzle?
Drizzle ORM schema definition uses TypeScript to declare tables with columns, types, and constraints. Once your schema is defined, Drizzle automatically infers types for your queries, ensuring type safety at compile time. You can then write queries using Drizzle's query builder, which provides autocomplete and type checking for all operations—select, insert, update, and delete—without sacrificing SQL expressiveness.
What are Drizzle ORM migrations and how do I manage them?
Drizzle ORM migrations track schema changes over time, allowing you to version control your database structure. Drizzle generates migration files automatically when you modify your schema, and you can apply or roll back migrations programmatically. This ensures your database stays in sync with your application code across development, staging, and production environments.
How can I avoid N+1 queries and optimize Drizzle ORM performance?
Drizzle ORM best practices for performance include using relational queries with proper joins to fetch related data in a single query, avoiding N+1 problems. Add database indexes on frequently queried columns, use pagination to limit result sets, and leverage Drizzle's query builder to construct efficient SQL. Monitor query execution and use Drizzle's type inference to catch inefficiencies early.
Can I use Drizzle ORM with PostgreSQL, SQLite, and serverless platforms?
Drizzle ORM supports multiple databases including PostgreSQL, SQLite, and Turso (SQLite edge database). It works seamlessly with serverless platforms by providing lightweight drivers that don't require persistent connections. This makes Drizzle ideal for edge computing and serverless functions where connection pooling and lightweight footprint matter.
What makes Drizzle ORM different from other TypeScript ORMs?
Drizzle ORM is a lightweight TypeScript ORM that prioritizes SQL-like syntax and type safety without heavy abstractions. Unlike heavier ORMs, Drizzle keeps you close to SQL while providing full type inference, making it easier to write performant queries. Its minimal footprint and support for multiple databases, including edge platforms like Turso, make it ideal for modern full-stack applications.
SKILL.md
rendered from the published skill — quoted content, verbatim
Drizzle ORM Development Guidelines
You are an expert in Drizzle ORM, TypeScript, and SQL database design with a focus on type safety and performance.
Core Principles
- Drizzle embraces SQL - if you know SQL, you know Drizzle
- Schema-as-code serves as the single source of truth
- Type safety is enforced at compile time, catching errors before runtime
- Lightweight with minimal runtime overhead (~7.4kb min+gzip)
- Serverless-ready: works with Node.js, Bun, Deno, Cloudflare Workers
Schema Design
Basic Table Definition
```typescript import { pgTable, serial, text, varchar, timestamp, boolean, integer } from "drizzle-orm/pg-core";
export const users = pgTable("users", { id: serial("id").primaryKey(), email: varchar("email", { length: 255 }).notNull().unique(), name: text("name"), isActive: boolean("is_active").default(true), createdAt: timestamp("created_at").defaultNow(), updatedAt: timestamp("updated_at").defaultNow(), });
export const posts = pgTable("posts", { id: serial("id").primaryKey(), title:
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 1 file
drizzle-orm/SKILL.md