Back to Docs
Recipe
Cloudflare D1 Primer
Global SQLite at the edge. Zero cold starts, Workers-native, and priced per row read — not per database.
What is D1?
D1 is Cloudflare's serverless SQL database built on SQLite. Every database is replicated across Cloudflare's global network. Reads hit the nearest replica in single-digit milliseconds. Writes route through a primary and propagate automatically.
Why D1 over alternatives?
- No connection pooling. Workers connect via HTTP API — no TCP exhaustion.
- SQLite dialect. Full SQL, indexes, triggers, views. Familiar tooling.
- Row-based billing. Pay for rows read/written, not compute hours.
- Wrangler-native. Migrations, backups, and branching built into the CLI.
Quick start
npx wrangler d1 create meridian-db
npx wrangler d1 execute meridian-db --file=./schema.sqlSchema file contains standard CREATE TABLE statements. Wrangler applies them transactionally.
Worker binding
export default {
async fetch(req, env) {
const { results } = await env.DB
.prepare("SELECT * FROM users WHERE id = ?")
.bind(userId)
.all()
return Response.json(results)
}
}Limits to know
- 10 GB max per database.
- 100 MB max per row.
- Writes per database: 1,000/second (burst).
- Bound parameters capped at 100 per query.
Meridian uses D1 for license state, session tokens, and audit logs. Read the full integration guide for schema patterns and migration workflows.