drizzle-sqlite

v2026.09.24

Drizzle ORM targeting SQLite (better-sqlite3, libsql/Turso, bun:sqlite, Cloudflare D1, expo-sqlite, op-sqlite). Covers schema definition (column modes, primary keys, foreign keys, indexes), drizzle-kit migrations (generate vs push, renames, custom SQL), the query builder (selects, upserts, returning, EXPLAIN), the relational query builder (relations(), `with`, partial columns), transactions and `db.batch()`, prepared statements with `sql.placeholder()`, connection pragmas (WAL, foreign_keys, busy_timeout), and Drizzle type inference (`$inferSelect`, `$inferInsert`, `$type<>`, drizzle-zod). Use when writing, reviewing, or refactoring Drizzle code for SQLite. Trigger even if the user doesn't say "performance" — schema/migration choices made now are expensive to reverse later, and SQLite-specific traps (single-writer model, no native booleans/dates, ALTER TABLE limits, FK pragma off by default) catch teams who reach for Drizzle without reading the SQLite docs.

GitHub
安装命令
npx skhub add pproenca/drizzle-sqlite
Markdown
SKILL.md

dot-skills Drizzle SQLite Best Practices

Library-reference skill for Drizzle ORM with SQLite-family backends. 45 rules across 8 categories, ordered by execution-lifecycle impact: schema → migrations → query → relations → transactions → performance → connection → types.

When to Apply

Reference these guidelines when:

  • Defining sqliteTable schemas — choosing column types, primary keys, indexes, foreign keys
  • Running drizzle-kit generate / migrate / push, or hand-editing a migration SQL file
  • Writing queries with db.select(), db.insert(), db.update(), db.delete()
  • Reaching for nested data with db.query.* and the relational query builder
  • Wrapping multi-statement writes in db.transaction() or db.batch() (libsql/Turso/D1)
  • Optimizing a hot-path query with .prepare() + sql.placeholder() or covering indexes
  • Setting up the Drizzle client (pragmas, driver choice, singleton lifecycle)
  • Wiring database types into application code ($inferSelect, drizzle-zod, JSON shapes)

The skill is not specific to one driver — it covers behavior shared across better-sqlite3, libsql, bun:sqlite, expo-sqlite, op-sqlite, and Cloudflare D1, calling out driver-specific deviations where they exist.

Architectural Context

SQLite is unusual among production databases:

  • No client/server. The "connection" is a file open. There is no connection pool, no auth, no network in the local-file case.
  • Single writer. One writer at a time, no matter how many connections. Reads can be parallel under WAL.
  • No native booleans or dates. Everything is INTEGER, REAL, TEXT, BLOB, or NULL — Drizzle column modes encode the rest.
  • Limited ALTER TABLE. Only RENAME COLUMN, ADD COLUMN, DROP COLUMN. Type changes and constraint additions need a table rebuild.
  • Foreign keys off by default. PRAGMA foreign_keys = ON is per-connection and not persistent.

Many rules in this skill exist because Drizzle's API abstracts over PostgreSQL/MySQL/SQLite uniformly — but the underlying SQLite engine has constraints that show up at runtime if you treat it like Postgres.

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Schema DefinitionCRITICALschema-
2Migrations & Drizzle KitCRITICALmigrate-
3Query BuildingHIGHquery-
4RelationsHIGHrel-
5Transactions & BatchingMEDIUM-HIGHtx-
6Prepared Statements & Hot PathsMEDIUM-HIGHperf-
7Connection & Driver SetupMEDIUMconn-
8Type InferenceMEDIUMtypes-

Quick Reference

1. Schema Definition (CRITICAL)

2. Migrations & Drizzle Kit (CRITICAL)

3. Query Building (HIGH)

4. Relations (HIGH)

5. Transactions & Batching (MEDIUM-HIGH)

6. Prepared Statements & Hot Paths (MEDIUM-HIGH)

7. Connection & Driver Setup (MEDIUM)

8. Type Inference (MEDIUM)

How to Use

Read the relevant category overview in references/_sections.md, then the specific rule files for detailed explanations and code examples. Each rule has incorrect-vs-correct examples — apply the correct pattern to the code under review.

For complex changes (schema redesign, migration strategy, performance work), read all rules in the affected category before deciding.

Reference Files

FileDescription
references/_sections.mdCategory definitions and ordering
assets/templates/_template.mdTemplate for new rules
metadata.jsonVersion and reference information

Related Skills

  • effect-ts — When the application is Effect-based; Drizzle integrates via Effect.tryPromise.
  • nextjs-bundle-optimizer — For Next.js apps reaching for SQLite as the data layer.
  • better-auth — Often paired with Drizzle SQLite for auth tables; see better-auth-scaffold for table generation.
发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.24

发布时间

Sep 24, 2026

分类

未分类

许可证

MIT

源路径

skills/.experimental/drizzle-sqlite

默认分支

master

最新提交

cf93c57

Tree SHA

afbb575