leonanpereirapinto/ai-utils/drizzle-orm

Claude Code and agent skill by leonanpereirapinto/ai-utils

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Expert guide for Drizzle ORM best practices, including schema definitions, queries, mutations, transactions, migrations, and performance optimization. Use when working with Drizzle ORM, database schemas, queries, or migrations.

Install

npx vskill@latest install leonanpereirapinto/ai-utils/drizzle-orm

SKILL.md

The same SKILL.md was published earlier as renan-rmsantos-tech/financial-agent/drizzle-orm.

Drizzle ORM Developer Guide

This skill provides guidelines, patterns, and best practices for working with Drizzle ORM in this project.

Quick Start

For detailed development guidelines, patterns, and code examples, refer to references/patterns.md.

Core Philosophy

  • Type-Safe by Default: Leverage TypeScript and Drizzle's type inference to catch database errors at compile time
  • Performance First: Use prepared statements and query optimization techniques
  • SQL Transparency: Keep SQL queries readable and avoid over-abstraction
  • Minimal Overhead: Drizzle is a thin layer - use it accordingly without unnecessary complexity

Common Tasks

Schema Definition

Organize schemas by domain in separate files. Use fluent constraint chaining and add indexes for frequently queried columns.

typescript
export const users = pgTable('users', {
id: uuid('id').primaryKey().defaultRandom(),
email: varchar('email', { length: 255 }).notNull().unique(),
createdAt: timestamp('created_at').defaultNow().notNull(),
});
Type Exports

Always export table types for use in your application:

typescript
export type User = typeof users.$inferSelect;
export type NewUser = typeof users.$inferInsert;
Prepared Statements

Use prepared statements for frequently executed queries for extreme performance benefits:

typescript
export const getUserById = db
.select()
.from(users)
.where(eq(users.id, sql.placeholder('id')))
.prepare();
// Usage
const user = await getUserById.execute({ id: userId });
Transactions

Use transactions for multi-step operations to maintain data consistency:

typescript
return db.transaction(async (tx) => {
const [user] = await tx.insert(users).values(userData).returning();
const [profile] = await tx.insert(profiles).values({ userId: user.id, ...profileData }).returning();
return { user, profile };
});

Migration Commands

CRITICAL: Always use package scripts for migrations. Never call drizzle-kit directly.

  • Backend: pnpm run db:generate (generates migration)
  • Backend: pnpm run db:migrate (applies migrations)
  • Landing: pnpm run db:generate (generates migration)
  • Landing: pnpm run db:migrate (applies migrations)

Code Organization

db/
index.ts (Drizzle client initialization)
schema/
users.ts (User table & relations)
posts.ts (Post table & relations)
queries/
users.ts (User query functions)
posts.ts (Post query functions)
migrations/ (Auto-generated migration files)

Common Pitfalls to Avoid

  1. Missing Indexes: Always index columns used in WHERE, JOIN, and ORDER BY clauses
  2. Unbounded Queries: Always use limit() and offset() for user-facing queries
  3. Unsafe Raw SQL: Never concatenate user input into raw SQL - use sql.placeholder()
  4. N+1 Queries: Use eager loading with with() or batch queries
  5. Missing Transactions: Wrap multi-step operations in transactions

Validation Checklist

Before finishing a task involving Drizzle ORM:

  • [ ] Check schema definitions have proper indexes for queried columns
  • [ ] Verify prepared statements are used for repeated queries
  • [ ] Ensure transactions wrap multi-step operations
  • [ ] Use package scripts for migrations (never call drizzle-kit directly)
  • [ ] Run type checks (pnpm run typecheck) and tests (pnpm run test)

For detailed rules and code examples, consult references/patterns.md.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/leonanpereirapinto/ai-utils/drizzle-orm/badge)](https://verified-skill.com/skills/leonanpereirapinto/ai-utils/drizzle-orm)

Something wrong with this skill or its page? Tell us.