---
name: "drizzle-orm-type-safe-sql"
description: "Write SQL-like database queries with zero runtime overhead and 100% type safety using Drizzle ORM."
metadata:
  author: "Drizzle Team"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "define drizzle table schema"
  - "drizzle relational query db.query"
  - "drizzle query builder"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Drizzle ORM Lightweight SQL-First Type-Safe Database Layer

Implements Drizzle ORM: defining schemas with pgTable / mysqlTable / sqliteTable, relational queries (db.query), query builder (select, insert, update, delete), prepared statements, and transactions.

## When to Invoke
Invoke this skill whenever you need to:
- define drizzle table schema
- drizzle relational query db.query
- drizzle query builder

## Execution SOP & Rules
1. Define schema in src/db/schema.ts using pgTable, serial, text, and timestamp.
2. Initialize database: const db = drizzle(postgres(connectionString), { schema }).
3. Query with relations: await db.query.users.findMany({ with: { posts: true } }).
4. Use query builder for complex SQL: await db.select().from(users).where(eq(users.id, 1)).

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
