skillfed

postgres-drizzle

Build type-safe database applications pairing PostgreSQL with Drizzle ORM. This skill covers schema design, relational queries, migrations via drizzle-kit, connection pooling, and common performance pitfalls like N+1 queries and missing indexes. Includes decision trees for modeling relationships and diagnosing slow queries.

postgres-drizzle helps you build type-safe PostgreSQL applications using Drizzle ORM with schema patterns, queries, and migrations.

AI-generated summary based on this skill's SKILL.md

55 3 MIT updated by ccheney

Install

ccheney/robust-skills/postgres-drizzle · repository language: JavaScript

CLI (skillfed)coming soon
git clone https://github.com/ccheney/robust-skills
cp -r robust-skills/skills/postgres-drizzle ~/.claude/skills/postgres-drizzle

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

How do I set up type-safe PostgreSQL with Drizzle ORM?

postgres-drizzle teaches you to initialize a PostgreSQL database with Drizzle ORM by installing drizzle-orm and drizzle-kit, configuring your database connection, and defining type-safe schemas. You'll learn to connect via environment variables, set up connection pooling for production, and use drizzle-kit to generate and apply migrations. The skill covers both local development and deployment patterns.

What does drizzle-kit generate migrate do and when do I use it?

postgres-drizzle explains that drizzle-kit generate creates migration files from your schema changes, while drizzle-kit migrate applies those migrations to your database. Use generate when your schema definition diverges from your database state, then migrate to sync them. The skill covers the push vs. generate vs. migrate workflow and helps you choose the right command for your development stage.

How can I avoid N+1 query problems in Drizzle relational queries?

postgres-drizzle teaches relational query patterns that prevent N+1 problems by using joins and eager loading instead of fetching parent records then looping to fetch children. You'll learn Drizzle's query builder syntax for left joins, inner joins, and relation helpers to load nested data in a single query. The skill includes examples of slow patterns and their optimized alternatives.

Why is my Drizzle query slow and how do I diagnose it?

postgres-drizzle covers query performance diagnosis by using PostgreSQL's EXPLAIN ANALYZE to identify missing indexes, sequential scans, and inefficient join orders. You'll learn to add indexes on foreign keys and frequently filtered columns, recognize N+1 patterns, and use connection pooling to avoid bottlenecks. The skill includes decision trees for common slow-query scenarios.

How do I model many-to-many relationships in Drizzle ORM?

postgres-drizzle teaches many-to-many modeling by creating a junction table with foreign keys to both parent tables, then defining Drizzle relations to query through it. You'll learn schema design patterns, how to insert and query junction records, and when to add extra columns (like timestamps) to the junction table. Examples cover both simple and complex many-to-many scenarios.

What connection pooling strategy should I use for Drizzle in production?

postgres-drizzle covers connection pooling setup using PgBouncer or native pool options in your Drizzle client, explaining pool size tuning, idle timeout configuration, and deployment patterns. You'll learn why pooling matters for serverless environments, how to monitor pool exhaustion, and best practices for graceful shutdown. The skill includes configuration examples for common hosting platforms.

SKILL.md

rendered from the published skill — quoted content, verbatim

PostgreSQL + Drizzle ORM

Type-safe database applications with PostgreSQL 17/18 and Drizzle ORM.

Version Check (do this first)

Drizzle's API changed significantly between the stable 0.x line and v1.0. Check package.json before writing code, because the two relations APIs are incompatible and must not be mixed:

drizzle-orm version Relations API Query filters
^0.x (npm latest) relations() per table, drizzle(client, { schema }) where: eq(users.id, id)
1.0.0-beta.* / 1.0.0-rc.* defineRelations() once for all tables, drizzle(client, { relations })

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 9 files
skills/postgres-drizzle/README.md
skills/postgres-drizzle/SKILL.md
skills/postgres-drizzle/references/CHEATSHEET.md
skills/postgres-drizzle/references/MIGRATIONS.md
skills/postgres-drizzle/references/PERFORMANCE.md
skills/postgres-drizzle/references/POSTGRES.md
skills/postgres-drizzle/references/QUERIES.md
skills/postgres-drizzle/references/RELATIONS.md
skills/postgres-drizzle/references/SCHEMA.md

Related skills

Tags

type-safe-orm schema-versioning query-optimization connection-pooling relational-data migration-management postgres-features performance-tuning database-design