CtrlK
BlogDocsLog inGet started
Tessl Logo
SkillPublic

drizzle-orm

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.

72

Quality

91%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Passed

No findings from the security scan

SKILL.md
Quality
Evals
Security

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/

Repository

monkilabs/opencastle

Path

src/orchestrator/plugins/drizzle/skills/drizzle-orm/SKILL.md

Last updated
First committed

Is this your skill?

If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.