Agent skill · software engineering · secondsky
drizzle-orm-d1
| Type-safe ORM for Cloudflare D1 databases using Drizzle. Use when: building D1 database schemas, writing type-safe SQL queries, managing migrations with Drizzle Kit, defining table relations, implementing prepared statements, using D1 batch API, or encountering D1_ERROR, transaction errors, foreign key constraint failures, or schema inference issues.
Why this skill is useful
Provides specific commands and configurations for managing Cloudflare D1 databases that the AI wouldn't reliably generate on its own.
What it needs
Requires bun installed locally. Requires cloudflare account access. About 5k tokens when loaded. Last updated 2026-08-06. 204 stars on the source repository.
What this skill does
Drizzle ORM for Cloudflare D1 Status: Production Ready ✅ Last Updated: 2025-12-14 Latest Version: drizzle-orm@0.45.2, drizzle-kit@0.31.10 Dependencies: cloudflare-d1, cloudflare-worker-base --- Quick Start (10 Minutes) 1. Install Drizzle 2. Configure Drizzle Kit Create drizzle.config.ts: drizzle-kit 0.30/0.31 note: dialect and dbCredentials are now strictly validated. A config that omits dialect or uses the old connectionString/ uri keys will fail validation. For D1 use dialect: 'sqlite' + driver: 'd1-http' with accountId/databaseId/token (or wrangler-based credentials). The runtime migrate() signature in drizzle-orm/<driver>/migrator is unchanged from 0.36 → 0.45 (it changes only in 1.0-beta, which is out of scope for ^0.45). 3. Define Schema Create src/db/schema.ts: 4. Generate & Apply Migrations 5. Query in Worker --- Critical Rules Always Do Rule Why ------ ----- Use drizzle-kit generate for migrations Never write SQL manually Test migrations locally first --local before --remote Use .get() for single results Returns first row or undefined Use db.batch() for transactions D1 doesn't support SQL BEGIN/COMMIT Use integer with mode: 'timestamp' for dates D1 has no native date type Use .$defaultFn() for dynamic defaults Not .default() for functions Never Do Rule Why ------ ----- Use SQL BEGIN TRANSACTION D1 requires batch API (Error #1) Mix drizzle-kit migrate and wrangler apply Use Wrangler only Use drizzle-kit push for production Use generate + apply Commit credentials in drizzle.config.ts Use env vars Use .default() for function calls Use .$defaultFn() instead --- Top 5 Critical Errors # Error Solution --- ------- ---------- 1 D1ERROR: Cannot use BEGIN TRANSACTION Use db.batch([...]) instead of db.transaction() 2 FOREIGN KEY constraint failed Define cascading: .references(() => users.id, { onDelete: 'cascade' }) 3 env.DB is undefined Ensure binding in wrangler.jsonc matches env.DB 4 No such module "wrangler" Use import { drizzle } from 'drizzle-orm/d1' 5 Type inst …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills secondsky/drizzle-orm-d1