3.0 KiB
Agent Shell Transcript
Agent: Claude Code Started: 2026-03-03 15:24:13 Working Directory: /home/fenix/napi/
User (2026-03-03 15:24:13)
how can i use SQLite on Cloudflare services ?
Agent's Thoughts (2026-03-03 15:24:15)
The user is asking about using SQLite on Cloudflare services. This is a general knowledge question, not related to the napi project. Let me answer from what I know and search for current info.
Cloudflare has D1, which is their SQLite-based database service for Workers.
Agent (2026-03-03 15:24:17)
Cloudflare offers D1, their native SQLite-at-the-edge database. Here's the quick rundown:
Cloudflare D1
D1 is a serverless SQLite database built into the Cloudflare Workers platform. Your data lives on Cloudflare's network, and queries run close to your users.
Key characteristics
- Real SQLite — standard SQL syntax, same engine
- Serverless — no connection pools, no provisioning
- Integrated with Workers — first-class binding, no external drivers
- Read replicas at the edge — writes go to a primary, reads are distributed
- Free tier available — 5M reads/day, 100K writes/day, 5GB storage
Minimal example (Worker + D1)
// wrangler.toml
// [[d1_databases]]
// binding = "DB"
// database_name = "my-db"
// database_id = "xxx-xxx-xxx"
export default {
async fetch(request, env) {
// Create table
await env.DB.exec("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)");
// Insert
await env.DB.prepare("INSERT INTO users (name) VALUES (?)").bind("Fénix").run();
// Query
const { results } = await env.DB.prepare("SELECT * FROM users").all();
return Response.json(results);
}
};
Setup steps
# 1. Create database
npx wrangler d1 create my-db
# 2. Add binding to wrangler.toml (output from step 1)
# 3. Run migrations
npx wrangler d1 execute my-db --local --file=./schema.sql # local dev
npx wrangler d1 execute my-db --remote --file=./schema.sql # production
# 4. Deploy
npx wrangler deploy
Other SQLite-adjacent options on Cloudflare
| Option | Use case |
|---|---|
| D1 | Primary choice — native SQLite, serverless, edge-distributed |
| Durable Objects + SQLite | Per-object embedded SQLite (since 2024) — good for per-user/per-room state |
| Hyperdrive | Not SQLite — connection pooler for external Postgres/MySQL |
D1 limitations to know
- Max DB size: 10GB (free: 500MB)
- Row size: 1MB max
- Single writer: writes serialize through one primary location
- No raw file access: you interact via SQL bindings only, not
.sqlitefiles - Transactions supported but with some restrictions (no nested, no savepoints)
For your napi context specifically — if you ever wanted to move from flat notas.md files to a DB-backed approach on Cloudflare, D1 would be the natural fit. Though the current file-based architecture is perfectly fine for 40 students.
Want me to dig deeper into any specific aspect (D1 pricing, Durable Objects SQLite, migrations, etc.)?