Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
oakoss avatar

Drizzle Orm

  • 137 installs
  • 14 repo stars
  • Updated March 2, 2026
  • oakoss/agent-skills

Model schemas, write type-safe queries, and run migrations with Drizzle ORM while implementing backend data layers.

About

Guides agents to implement backend data layers with Drizzle ORM: define schemas, relations, and migrations; write type-safe queries; and integrate database access cleanly into Node and TypeScript APIs.

  • Type-safe queries
  • Schema modeling
  • SQL migrations
  • Relation mapping
  • Lightweight ORM

Drizzle Orm by the numbers

  • 137 all-time installs (skills.sh)
  • +8 installs in the week ending Aug 4, 2026 (Skillselion tracking)
  • Ranked #287 of 911 Databases skills by installs in the Skillselion catalog
  • Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/oakoss/agent-skills --skill drizzle-orm

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs137
repo stars14
Last updatedMarch 2, 2026
Repositoryoakoss/agent-skills

What it does

Model schemas, write type-safe queries, and run migrations with Drizzle ORM while implementing backend data layers.

Files

SKILL.mdMarkdownGitHub ↗

Drizzle ORM

Overview

Drizzle ORM is a lightweight, type-safe TypeScript ORM that maps directly to SQL for PostgreSQL, MySQL, and SQLite. It provides both a SQL-like query builder and a relational queries API, with zero dependencies and full serverless compatibility. Use Drizzle when you need compile-time type safety with SQL-level control; avoid it when you need a full active-record ORM with automatic migrations (use Prisma) or when working with MongoDB/NoSQL databases.

Quick Reference

PatternAPIKey Points
Schema definitionpgTable('name', { columns }, (t) => [indexes])Third arg returns array of indexes/constraints
Column typestext(), integer(), boolean(), timestamp()Import from drizzle-orm/pg-core
Type inferencetypeof table.$inferSelect, $inferInsertDerive TS types directly from schema
Relational queriesdb.query.table.findMany({ with, where })Requires schema passed to drizzle() client
SQL-like queriesdb.select().from(table).where()Chainable, returns array of rows
Insertdb.insert(table).values({}).returning().returning() for getting inserted rows
Updatedb.update(table).set({}).where().returning()Always include .where() to avoid full-table updates
Deletedb.delete(table).where()Always include .where() to avoid full-table deletes
Upsert.onConflictDoUpdate({ target, set })Chain after .insert().values()
Transactionsdb.transaction(async (tx) => { ... })Auto-rollback on thrown errors
Filterseq(), and(), or(), inArray(), sql\\``Import operators from drizzle-orm
Relationsrelations(table, ({ one, many }) => ({}))Declares logical relations for relational queries
Generate migrationsdrizzle-kit generateCreates SQL migration files from schema diff
Apply migrationsdrizzle-kit migrate or migrate() in codeApplies pending migrations to database
Push schemadrizzle-kit pushDirect schema push without migration files
Prepared statementsdb.select().from(t).where(eq(t.id, sql.placeholder('id'))).prepare()Reusable parameterized queries
ViewspgView('name').as(qb => ...)Regular and materialized views
$count utilitydb.$count(table, filter?)Shorthand count, usable as subquery
Generated columnstext().generatedAlwaysAs(() => sql\...\)Computed columns (virtual or stored)
Check constraintscheck('name', sql\condition\)Row-level validation at database level

Common Mistakes

MistakeCorrect Pattern
Missing .returning() on insert/updateChain .returning() to get back inserted/updated rows
Omitting .where() on update/deleteAlways provide .where() to avoid affecting all rows
Using any for query result typesUse $inferSelect / $inferInsert for type-safe results
Not passing schema to drizzle() clientPass { schema } to enable db.query relational API
Forgetting indexes on foreign key columnsAdd explicit indexes for columns used in joins/lookups
Wrapping related writes without a transactionUse db.transaction() for multi-table mutations
Using raw column names with casing: 'snake_case'With casing option, define columns in camelCase without name arg
Declaring relations but missing the inverseBoth sides of a relation need declarations for relational queries
Using serial() in new PostgreSQL schemasPrefer integer().generatedAlwaysAsIdentity() (modern approach)
Not handling findFirst returning undefinedCheck for undefined before accessing properties
Importing column types from wrong dialect moduleUse drizzle-orm/pg-core for PostgreSQL, mysql-core, sqlite-core
Using .references() instead of relations().references() is SQL foreign key; relations() is for query API

Delegation

If the tanstack-query skill is available, delegate client-side caching and server state management to it.
Otherwise, recommend: npx skills add oakoss/agent-skills --skill tanstack-query

>

If the tanstack-start skill is available, delegate server function patterns for database access to it.
Otherwise, recommend: npx skills add oakoss/agent-skills --skill tanstack-start

>

If the electricsql skill is available, delegate Electric setup, shape configuration, and write patterns to it.
Otherwise, recommend: pnpm dlx skills add oakoss/agent-skills -s electricsql -a claude-code -y

>

If the pglite skill is available, delegate PGlite-specific configuration, extensions, and browser storage patterns to it.
Otherwise, recommend: pnpm dlx skills add oakoss/agent-skills -s pglite -a claude-code -y
  • Schema validation: Use drizzle-zod to generate Zod schemas from Drizzle tables for input validation
  • Query pattern discovery: Use Explore agent
  • Code review: Delegate to code-reviewer agent

References

  • Schema definition, column types, constraints, indexes, and type inference
  • Relational queries, SQL-like API, joins, subqueries, and aggregations
  • Insert, update, delete, upsert, and transactions
  • Relations: one, many, nested with clauses, self-referencing
  • Migrations: drizzle-kit generate, migrate, push, pull, studio
  • Filter operators: eq, ne, gt, lt, like, inArray, sql template
  • Views, materialized views, generated columns, check constraints, $count, batch API
  • ElectricSQL + PGlite integration: driver setup, schema-to-shape mapping, type inference, local sync

Related skills

Databasesbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.