cloudflare-d1

Automate Cloudflare D1 database lifecycle including migrations and prepared statements for Workers.

961|99|Updated Oct 20, 2025
One-click install
npx skills add https://github.com/jezweb/claude-skills --skill cloudflare-d1-jezweb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cloudflare-d1
Source: https://github.com/jezweb/claude-skills/tree/main/skills/cloudflare-d1
Command: npx skills add https://github.com/jezweb/claude-skills --skill cloudflare-d1-jezweb

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires wrangler, @cloudflare/workers-types, and includes references (resource) and templates (resource) components.

What problem does it solve?

This Skill eliminates the complexity of setting up and managing Cloudflare D1 databases, saving developers thousands of tokens and hours of configuration time.

Core Features & Use Cases

  • Database Management: Create D1 databases, configure bindings, and manage SQL migrations with automated workflows.
  • Query Optimization: Write type-safe D1 queries with prepared statements, batch operations, and automatic error handling.
  • Use Case: Imagine you're building a user management system for your Cloudflare Worker. Use this Skill to automatically generate the complete database schema, migration files, and optimized query patterns for your application.

Quick Start

Use the cloudflare-d1 skill to create a new database and set up user authentication tables with proper indexes and foreign key relationships.

npx wrangler d1 create my-app-db npx wrangler d1 migrations create my-app-db create_users_table npx wrangler d1 migrations apply my-app-db --local const user = await env.DB.prepare('SELECT * FROM users WHERE email = ?').bind('[email protected]').first();

Frequently Asked Questions about cloudflare-d1

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up and manage SQLite databases on Cloudflare Workers?

Cloudflare D1 lets you create and manage SQLite databases directly from Workers. Use wrangler to create databases, configure bindings in your worker configuration, and execute queries with prepared statements for type safety and performance.

How do I apply database migrations with Cloudflare D1?

D1 migrations are SQL files you create and apply using wrangler commands. Write idempotent migration scripts, apply them locally for testing, then deploy to your live database. Migrations run in sequence to evolve your schema safely.

Can I use prepared statements and batch queries with D1?

Yes, D1 enforces prepared statements with parameter binding to prevent SQL injection. Batch multiple queries together for better performance, and use the `.first()` or `.all()` methods to retrieve results efficiently.

What's the best way to handle errors when querying D1 databases?

D1 provides error handling patterns for query failures and connection issues. Wrap queries in try-catch blocks, validate input bindings, and implement fallback logic to ensure your Worker handles database errors gracefully.

Does D1 support both local development and remote databases?

D1 supports local development workflows using the wrangler CLI, letting you test migrations and queries offline. Switch to remote databases by deploying your Worker, with the same code working seamlessly in both environments.

Why use D1 instead of managing databases outside Cloudflare?

D1 runs SQLite on Cloudflare's edge network, eliminating external database latency and infrastructure complexity. It integrates natively with Workers, reduces query round trips, and simplifies deployment by colocating compute and storage.