cloudflare-d1
This skill streamlines Cloudflare D1 database setup by automating wrangler configuration, binding management, and migration workflows. It's built for developers using Claude Code CLI who need rapid database provisioning with minimal manual configuration overhead.
Cloudflare D1 streamlines setup through wrangler configuration. Start by creating a D1 database using `wrangler d1 create <database-name>`, then add the binding to your `wrangler.toml` file under the `[[d1_databases]]` section with your database ID. For migrations, create SQL files in a `migrations/` directory and apply them with `wrangler d1 migrations apply <database-name>`. The skill automates this configuration workflow, reducing manual setup overhead and enabling rapid database provisioning for developers using Claude Code CLI.
AI-generated summary based on this skill's SKILL.md
Install
secondsky/claude-skills/cloudflare-d1 · repository language: TypeScript
git clone https://github.com/secondsky/claude-skills
cp -r claude-skills/plugins/cloudflare-d1/skills/cloudflare-d1 ~/.claude/skills/cloudflare-d1Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How do I set up a Cloudflare D1 database with wrangler bindings and migrations?
Cloudflare D1 streamlines setup through wrangler configuration. Start by creating a D1 database using `wrangler d1 create <database-name>`, then add the binding to your `wrangler.toml` file under the `[[d1_databases]]` section with your database ID. For migrations, create SQL files in a `migrations/` directory and apply them with `wrangler d1 migrations apply <database-name>`. The skill automates this configuration workflow, reducing manual setup overhead and enabling rapid database provisioning for developers using Claude Code CLI.
What are the main D1 API methods for writing and optimizing SQL queries?
Cloudflare D1 provides three core API methods for query execution: `prepare()` for parameterized statements that prevent SQL injection and improve performance, `batch()` for executing multiple queries in a single request to reduce latency, and `exec()` for running raw SQL directly. The `prepare()` method is optimal for repeated queries with different parameters, while `batch()` minimizes round trips when executing several independent statements. Using these methods correctly ensures both security and performance optimization in your D1 applications.
What does the 'statement too long' D1 error mean and how do I fix it?
Cloudflare D1 enforces a statement size limit, and the 'statement too long' error occurs when your SQL query or batch exceeds this threshold. To resolve it, break large queries into smaller, focused statements and use the `batch()` API to execute them together, or split complex operations across multiple API calls. Additionally, review your query logic—overly nested subqueries or massive IN clauses can be refactored using joins or temporary tables. The skill helps identify and troubleshoot such D1 errors including 429 rate-limit issues and query failures.
How can I deploy read replicas and global replication for low-latency reads with D1?
Cloudflare D1 supports read replicas to distribute query load and reduce latency across regions. Enable replication in your D1 configuration, then route read-only queries to replica locations closest to your users. This is particularly valuable for edge-deployed applications where latency matters. Cloudflare D1 handles replication synchronization automatically, allowing you to design globally distributed applications without manual replica management. The skill guides you through replica setup and optimization strategies for low-latency read performance.
What are D1 schema design best practices for indexes, type affinity, and migrations?
Cloudflare D1 schema design should prioritize type affinity—use INTEGER, TEXT, REAL, and BLOB types correctly to ensure efficient storage and query performance. Create indexes on frequently queried columns (especially foreign keys and WHERE clause filters) to accelerate lookups, but avoid over-indexing as it slows writes. Structure migrations incrementally in separate SQL files, applying them in order via wrangler to maintain consistency across environments. The skill emphasizes these best practices to help you build performant, maintainable schemas that scale efficiently on D1.
How do I test Cloudflare D1 locally with wrangler before deploying?
Cloudflare D1 supports local testing through wrangler's local mode. Run `wrangler d1 execute <database-name> --local` to test queries against a local SQLite instance, or use `wrangler dev --local` to simulate your entire worker environment. This allows you to validate migrations, test query logic, and debug schema issues before production deployment. Local testing reduces deployment risk and iteration time, making it essential for development workflows. The skill integrates local testing patterns to streamline your development cycle.
SKILL.md
rendered from the published skill — quoted content, verbatim
Cloudflare D1
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 11 files
plugins/cloudflare-d1/skills/cloudflare-d1/SKILL.md
plugins/cloudflare-d1/skills/cloudflare-d1/references/2025-features.md
plugins/cloudflare-d1/skills/cloudflare-d1/references/best-practices.md
plugins/cloudflare-d1/skills/cloudflare-d1/references/limits.md
plugins/cloudflare-d1/skills/cloudflare-d1/references/metrics-analytics.md
plugins/cloudflare-d1/skills/cloudflare-d1/references/query-patterns.md
plugins/cloudflare-d1/skills/cloudflare-d1/references/read-replication.md
plugins/cloudflare-d1/skills/cloudflare-d1/references/setup-guide.md
plugins/cloudflare-d1/skills/cloudflare-d1/templates/d1-setup-migration.sh
plugins/cloudflare-d1/skills/cloudflare-d1/templates/d1-worker-queries.ts
plugins/cloudflare-d1/skills/cloudflare-d1/templates/schema-example.sql