Skip to content
Back to skills

Drizzle Orm

ASecurity

Drizzle ORM schemas, type-safe and relational queries, transactions and drizzle-kit migrations for PostgreSQL, MySQL and SQLite. Use when defining a Drizzle schema, writing Drizzle queries, or running drizzle-kit.

  • 80 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 3, 2026
ai-agentsgosqlapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned October 5, 2026

npx -y skills add monkilabs/opencastle --skill drizzle-orm --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Drizzle Orm?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Drizzle Orm
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/monkilabs-drizzle-orm/badge)](https://www.skillsdirectory.com/skills/monkilabs-drizzle-orm)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: drizzle-orm
description: "Drizzle ORM schemas, type-safe and relational queries, transactions and drizzle-kit migrations for PostgreSQL, MySQL and SQLite. Use when defining a Drizzle schema, writing Drizzle queries, or running drizzle-kit."
---

# Drizzle ORM

## Gotchas

- `drizzle(client, { schema })` — omit `{ schema }` and the `db.query.*` relational API silently does not exist.
- `relations()` is ORM-level metadata only and creates no constraint. Define `references(() => users.id, { onDelete: 'cascade' })` as well; you need both.
- Types come from `typeof table.$inferSelect` / `$inferInsert` — never hand-write them.
- SQL-like API (`db.select().from()`) for joins and aggregates; relational API (`db.query.x.findMany({ with: {...} })`) for nested reads. `insert`/`update`/`delete` give back nothing usable without `.returning()`.
- Inside `db.transaction(async (tx) => ...)` every call must use `tx`; a stray `db` call runs outside the transaction.
- Prepared statements need `sql.placeholder('id')` + `.prepare('name')`, then `.execute({ id })`.
- Partial selects (`db.select({ id: users.id })`) avoid loading unused columns; declare indexes in the table definition.

## drizzle-kit

- `generate` → review the SQL in the `out` dir → `migrate`. `push` is dev-only. Never edit generated SQL; fix the schema and regenerate. `check` validates migration history consistency.
- A column rename generates DROP + ADD, i.e. data loss. Hand-write the migration file instead — `ALTER TABLE users RENAME COLUMN old_name TO new_name;` — then `migrate` applies it.
- A new non-nullable column takes two migrations: add nullable → backfill → add `.notNull()` → migrate again.
- The programmatic migrator needs a single connection: `postgres(url, { max: 1 })`, then `migrate(drizzle(client), { migrationsFolder: './drizzle' })`, then close it.
- `drizzle.config.ts` must supply `dialect`, `schema`, `out`, and `dbCredentials.url` before any command runs.

Docs: https://orm.drizzle.team/

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…