cloudflare-d1

Enforce prepared statements and batch operations for Cloudflare D1 in Workers.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/stephanofer/finance-trackerv2 --skill cloudflare-d1-stephanofer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cloudflare-d1
Source: https://github.com/stephanofer/finance-trackerv2/tree/main/.opencode/skill/cloudflare-d1
Command: npx skills add https://github.com/stephanofer/finance-trackerv2 --skill cloudflare-d1-stephanofer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill simplifies building data layers on Cloudflare Workers by providing safe, prepared SQL access to Cloudflare D1, along with batch operations and Drizzle ORM integration.

Core Features & Use Cases

  • Safe, prepared statements for all D1 queries to prevent SQL injection.
  • Batch operations for atomic multiple-queries or inserts.
  • Drizzle ORM integration to model and query SQLite-based D1 schemas in Workers.
  • Deployment guidance for wrangler.toml bindings and environment setup.

Quick Start

Configure a Cloudflare Worker to connect to a D1 database, define a D1 binding (e.g., DB) in wrangler.toml, and implement a few representative queries using env.DB.prepare(...).bind(...).first()/all() in TypeScript.

Frequently Asked Questions about cloudflare-d1

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

FAQPage Schema
How do I run safe SQL queries in Cloudflare D1 using prepared statements?

To run safe SQL queries in Cloudflare D1, use prepared statements via env.DB.prepare(...).bind(...).first() or .all() in TypeScript. This pattern prevents SQL injection by separating query structure from input data, ensuring secure database access within your Workers environment.

How do I execute batch operations for multiple inserts in Cloudflare D1?

Execute batch operations in Cloudflare D1 using env.DB.batch() to run multiple queries atomically. This method allows you to group several prepared statements together, ensuring transactional updates or bulk inserts succeed or fail as a single unit.

Can I use Drizzle ORM with Cloudflare D1 and SQLite in Workers?

Yes, you can integrate Drizzle ORM with Cloudflare D1 to model and query SQLite-based schemas in Workers. This integration provides a typed query builder layer over D1, simplifying schema definitions and data interactions while maintaining safe prepared statement execution.

What wrangler.toml configuration is needed for a D1 database binding?

Configuring a D1 database binding in wrangler.toml requires defining a binding name, such as DB, linked to your D1 instance. This setup exposes the database connection to your Worker code, allowing you to access it directly through the env.DB object in TypeScript.

What's the best way to seed a Cloudflare D1 database with initial data?

The best way to seed a Cloudflare D1 database is by using batch operations with prepared statements. Grouping your initial insert queries into an atomic batch via env.DB.batch() ensures efficient, transactional data population while preventing injection vulnerabilities during setup.