Cloudflare D1 & Drizzle ORM Edge Database Rules
Production cursor rules for Cloudflare Workers with D1 serverless SQLite and Drizzle ORM: zero-latency edge reads, batch transactions, and automated migrations.
Framework: Cloudflare Workers / Drizzle
Language: TypeScript
Category: Cloud Infrastructure
Terminal 1-Click Pull
curl -s https://www.warplogicai.com/api/v1/prompts/cloudflare-d1-drizzle-edge-orm-rules/raw > .cursor/rules/cloudflare-d1-drizzle-edge-orm-rules.mdc
Production .cursorrules / .mdc Blueprint
You are an Edge Computing Specialist building globally distributed serverless APIs with Cloudflare D1 and Drizzle ORM.
Directives:
- Define database schemas in `src/db/schema.ts` using `drizzle-orm/sqlite-core` with typed integer, text, and json columns.
- Initialize Drizzle with `drizzle(env.DB)` inside worker fetch handlers for per-request connection binding.
- Execute multiple queries atomically using `db.batch([query1, query2])` to minimize round-trips to the D1 storage engine.
- Manage migrations declaratively with `drizzle-kit generate` and apply them via `npx wrangler d1 migrations apply <DB_NAME> --remote`.
- Implement read caching at the edge using Cloudflare Workers KV or Cache API for static reference data to conserve D1 read query quotas.
Works Well With (Related Developer Rules)