drizzle-orm-d1▌
jezweb/claude-skills · updated Apr 8, 2026
MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.
Type-safe D1 databases with Drizzle ORM, migrations, and batch API patterns for Cloudflare Workers.
- ›Includes schema definition, Drizzle Kit migrations, relations, and D1-specific batch API for transactions (D1 doesn't support SQL BEGIN)
- ›Prevents 18 documented errors including transaction failures, cascade data loss, 100-parameter limits, foreign key issues, and nested migration discovery
- ›Supports dynamic query building, upserts, logging, and Drizzle Studio for visual database browsin
Drizzle ORM for Cloudflare D1
Status: Production Ready ✅ Last Updated: 2026-02-03
Commands
| Command | Purpose |
|---|---|
/db-init |
Set up Drizzle ORM with D1 (schema, config, migrations) |
/migrate |
Generate and apply database migrations |
/seed |
Seed database with initial or test data |
| Latest Version: [email protected], [email protected], [email protected] | |
| Dependencies: cloudflare-d1, cloudflare-worker-base |
Quick Start (5 Minutes)
# 1. Install
npm install drizzle-orm
npm install -D drizzle-kit
# 2. Configure drizzle.config.ts
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './src/db/schema.ts',
out: './migrations',
dialect: 'sqlite',
driver: 'd1-http',
dbCredentials: {
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
databaseId: process.env.CLOUDFLARE_DATABASE_ID!,
token: process.env.CLOUDFLARE_D1_TOKEN!,
},
});
# 3. Configure wrangler.jsonc
{
"d1_databases": [{
"binding": "DB",
"database_name": "my-database",
"database_id": "your-database-id",
"migrations_dir": "./migrations" // CRITICAL: Points to Drizzle migrations
}]
}
# 4. Define schema (src/db/schema.ts)
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
export const users = sqliteTable('users', {
id: integer('id').primaryKey({ autoIncrement: true }),
email: text('email').notNull().unique(),
createdAt: integer('created_at', { mode: 'timestamp' }).$defaultFn(() => new Date()),
});
# 5. Generate & apply migrations
npx drizzle-kit generate
npx wrangler d1 migrations apply my-database --local # Test first
npx wrangler d1 migrations apply my-database --remote # Then production
# 6. Query in Worker
import { drizzle } from 'drizzle-orm/d1';
import { users } from './db/schema';
const db = drizzle(env.DB);
const allUsers = await db.select().from(users).all();
D1-Specific Critical Rules
✅ Use db.batch() for transactions - D1 doesn't support SQL BEGIN/COMMIT (see Issue #1)
✅ Test migrations locally first - Always --local before --remote
✅ Use integer with mode: 'timestamp' for dates - D1 has no native date type
✅ Use .$defaultFn() for dynamic defaults - Not .default() for functions
✅ Set migrations_dir in wrangler.jsonc - Points to ./migrations
❌ Never use SQL BEGIN TRANSACTION - D1 requires batch API
❌ Never use drizzle-kit push for production - Use generate + apply
❌ Never mix wrangler.toml and wrangler.jsonc - Use wrangler.jsonc only
Drizzle Kit Tools
Drizzle Studio (Visual Database Browser)
npx drizzle-kit studio
# Opens http://local.drizzle.studio
# For remote D1 database
npx drizzle-kit studio --port 3001
Features:
- Browse tables and data visually
- Edit records inline
- Run custom SQL queries
- View schema relationships
Migration Commands
| Command | Purpose |
|---|---|
drizzle-kit generate |
Generate SQL migrations from schema changes |
drizzle-kit push |
Push schema directly (dev only, not for production) |
drizzle-kit pull |
Introspect existing database → Drizzle schema |
drizzle-kit check |
Validate migration integrity (race conditions) |
drizzle-kit up |
Upgrade migration snapshots to latest format |
# Introspect existing D1 database
npx drizzle-kit pull
# Validate migrations haven't collided
npx drizzle-kit check
Advanced Query Patterns
Dynamic Query Building
Build queries conditionally with .$dynamic():
import { eq, and, or, like, sql } from 'drizzle-orm';
// Base query
function getUsers(filters: { name?: string; email?: string; active?: boolean }) {
let query = db.select().from(users).$dynamic();
if (filters.name) {
query = query.where(like(users.name, `%${filters.name}%`));
}
if (filters.email) {
query = query.where(eq(users.email, filters.email));
}
if (filters.active !== undefined) {
query = query.where(eq(users.active, filters.active));
}
return query;
}
// Usage
const results = await getUsers({ name: 'John', active: true });
Upsert (Insert or Update on Conflict)
import { users } from './schema';
// Insert or ignore if exists
await db.insert(users)
.values({ id: 1, email: '[email protected]', name: 'Test' })
.onConflictDoNothing();
// Insert or update specific fields on conflict
await db.insert(users)
.values({ id: 1, email: '[email protected]', name: 'Test' })
.onConflictDoUpdate({
target: users.email, // Conflict on unique email
set: {
name: sql`excluded.name`, // Use value from INSERT
updatedAt: new Date(),
},
});
⚠️ D1 Upsert Caveat: Target must be a unique column or primary key.
Debugging with Logging
import { drizzle } from 'drizzle-orm/d1';
// Enable query logging
const db = drizzle(env.DB, { logger: true });
// Custom logger
const db = drizzle(env.DB, {
logger: {
logQuery(query, params) {
console.log('SQL:', query);
How to use drizzle-orm-d1 on Cursor
AI-first code editor with Composer
Prerequisites
Before installing skills in Cursor, ensure your development environment meets these requirements:
- ›Cursor installed and configured on your development machine
- ›Node.js version 16.0+ with npm package manager (verify with
node --version) - ›Active project directory or workspace where you want to add drizzle-orm-d1
Execute installation command
Execute the skills CLI command in your project's root directory to begin installation:
The skills CLI fetches drizzle-orm-d1 from GitHub repository jezweb/claude-skills and configures it for Cursor.
Select Cursor when prompted
The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:
Verify installation
Confirm successful installation by checking the skill directory location:
Reload or restart Cursor to activate drizzle-orm-d1. Access the skill through slash commands (e.g., /drizzle-orm-d1) or your agent's skill management interface.
Security & Verification Notice
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.
List & Monetize Your Skill
Submit your Claude Code skill and start earning
Use Cases▌
User Story & Requirements Generation
Create detailed user stories, acceptance criteria, and feature specs
Example
Generate user stories for 'password reset feature' with acceptance criteria, edge cases, and test scenarios
Reduce spec writing time by 50%, ensure comprehensive coverage
Competitive Analysis
Research competitors, compare features, identify gaps
Example
Analyze 5 competitor products, create feature comparison matrix, suggest differentiation opportunities
Complete competitive research in 2 hours instead of 2 days
Roadmap Prioritization
Evaluate features using frameworks (RICE, ICE, Kano) and create prioritized backlogs
Example
Score 20 feature ideas using RICE framework, generate prioritized roadmap with rationale
Make data-driven prioritization decisions faster
Stakeholder Communication
Draft PRDs, status updates, and stakeholder presentations
Example
Create executive summary of Q3 roadmap, monthly progress report, feature launch announcement
Save 3-5 hours/week on communication overhead
Implementation Guide▌
Prerequisites
- ›Claude Desktop or compatible AI client
- ›Access to product documentation and roadmap tools (Jira, Notion, etc.)
- ›Understanding of product management frameworks (RICE, Jobs-to-be-Done, etc.)
- ›Stakeholder contact information and communication channels
Time Estimate
30-60 minutes to see productivity improvements
Installation Steps
- 1.Install product management skill
- 2.Start with user story generation for known feature
- 3.Progress to competitive analysis: research 2-3 competitors
- 4.Use for roadmap prioritization: apply RICE/ICE scoring
- 5.Draft stakeholder communications and refine based on feedback
- 6.Build template library for recurring PM tasks
- 7.Share effective prompts with product team
Common Pitfalls
- ⚠Not validating competitive research—verify facts before sharing
- ⚠Accepting user stories without involving engineering team
- ⚠Over-relying on frameworks without qualitative judgment
- ⚠Not customizing outputs to company culture and communication style
- ⚠Skipping stakeholder validation of generated requirements
Best Practices▌
✓ Do
- +Validate research and competitive analysis with real data
- +Collaborate with engineering when generating technical requirements
- +Customize frameworks and templates to your company context
- +Use skill for first drafts, refine with stakeholder input
- +Document successful prompt patterns for PM tasks
- +Combine AI efficiency with human judgment and intuition
✗ Don't
- −Don't publish competitive analysis without fact-checking
- −Don't finalize user stories without engineering review
- −Don't make prioritization decisions solely on AI scoring
- −Don't skip customer validation of generated requirements
- −Don't ignore company-specific context and culture
💡 Pro Tips
- ★Provide context: company goals, constraints, customer feedback
- ★Ask for alternatives: 'Show 3 ways to prioritize this roadmap'
- ★Request stakeholder-specific formatting: 'Executive summary vs. engineering spec'
- ★Use skill for 70% generation + 30% customization to company needs
When to Use This▌
✓ Use When
Use for user story writing, competitive research, roadmap prioritization, stakeholder communication, and PRD drafting. Best for reducing repetitive documentation and research work.
✗ Avoid When
Avoid for strategic product vision (requires deep customer empathy), pricing decisions (needs market and financial expertise), or when face-to-face customer discovery is more valuable than speed.
Learning Path▌
- 1Basic: user stories, feature specs, status updates
- 2Intermediate: competitive analysis, prioritization frameworks, PRDs
- 3Advanced: product strategy, go-to-market planning, OKR setting
- 4Expert: product vision, market positioning, business model innovation
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.8★★★★★34 reviews- ★★★★★Diego Diallo· Dec 20, 2024
drizzle-orm-d1 reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Chaitanya Patil· Dec 16, 2024
drizzle-orm-d1 has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Pratham Ware· Dec 12, 2024
Registry listing for drizzle-orm-d1 matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Isabella Khanna· Nov 19, 2024
drizzle-orm-d1 fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Ishan Yang· Nov 15, 2024
Registry listing for drizzle-orm-d1 matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Chen White· Nov 11, 2024
drizzle-orm-d1 is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- ★★★★★Piyush G· Nov 7, 2024
Solid pick for teams standardizing on skills: drizzle-orm-d1 is focused, and the summary matches what you get after install.
- ★★★★★Shikha Mishra· Oct 26, 2024
We added drizzle-orm-d1 from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Chen Bansal· Oct 10, 2024
Registry listing for drizzle-orm-d1 matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Li Singh· Oct 6, 2024
drizzle-orm-d1 fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
showing 1-10 of 34