cflare d1

D1 Serverless SQLite Database

Serverless SQL

Manage Cloudflare D1 serverless SQLite databases, execute raw SQL queries, and apply schema migrations.

$ cflare d1 <list|query|backup> <database> [options]

📖 Full Explanation

Cloudflare D1 is a serverless, relational database built on SQLite distributed across Cloudflare's global network. \1 provides an interactive terminal query engine to inspect tables, debug schema changes, and run instant SQL commands.

⚙️ Command Options & Flags

Option / Flag Description Default
-q, --query <sql> SQL statement to execute against the database -
-f, --file <sql-file> Execute SQL script file (for migrations) -
--json Return query results in JSON format false

🔬 Technical Corollary & Edge Mechanics

Executes queries via \1. Supports transactions, automatic read replication to edge locations nearest users, and consistent writes routed to the primary region.

🎯 Real-World DevOps Use Cases

Interactive Database Debugging

Quickly inspect user rows or system settings without opening an external SQL GUI.

$ cflare d1 query prod-db -q "SELECT id, email, created_at FROM users LIMIT 5"

Applying Edge Schema Migrations

Run migration scripts directly from CI/CD pipelines before deploying new Workers code.

$ cflare d1 query prod-db -f migrations/0002_add_index.sql

💻 Live Output Simulation

$ cflare d1 query prod-db -q "SELECT id, status, count(*) FROM orders GROUP BY status;"
┌────┬───────────┬──────────┐
│ id │ status    │ count(*) │
├────┼───────────┼──────────┤
│ 1  │ completed │ 1,429    │
│ 2  │ pending   │ 38       │
│ 3  │ refunded  │ 12       │
└────┴───────────┴──────────┘
✔ Executed in 14ms (Rows read: 1479, Rows written: 0)