2.7 KiB
+++ title = "[TRIAGE] Local dev config: Turso (file SQLite) vs D1 binding selection strategy" priority = 8 status = "done" ticket_type = "task" dependencies = [] +++
This is a triage decision ticket. It must be resolved before dependent implementation tickets can proceed. Local dev config: should the API use Turso (file-backed SQLite via libsql) or a D1 binding (via wrangler dev) for local development? How is the selection made at runtime? 1. **Turso/libsql** — lightweight local SQLite file, no Cloudflare account needed. Connection string via env var. SQLx-compatible. 2. **Wrangler D1 local** — `wrangler dev` spins up a local D1 emulator. Closer to production but requires wrangler and a Cloudflare account even locally. 3. **Plain SQLite via sqlx** — use sqlx's SQLite driver with a local file. No Turso dependency needed for dev. **Chosen approach: rusqlite with a local SQLite file — a variant of Option 3, but using rusqlite instead of sqlx.**This decision is a direct consequence of TRIAGE e8a330 (already resolved): SQLx is NOT compatible
with Cloudflare Workers/D1 at all. The chosen architecture is cfg(target_arch = "wasm32") compile-time split:
wasm32(production) → workers-rsD1Databasebindings- native (local dev + tests) →
rusqlite+tokio-rusqlitewith a local.sqlitefile
Rationale for rusqlite over Turso:
- No additional dependency or service (Turso = libsql client + server/cloud)
rusqlitewithfeatures = ["bundled"]compiles SQLite in — zero system dependenciescargo runjust works without any account, credentials, or external toolingcargo testworks the same way — tests use the rusqlite path automatically
Rationale for rusqlite over wrangler D1 local:
- No wrangler, no Cloudflare account required for local dev or CI
- Eliminates a major developer friction point
- Integration tests use
NativeRepository(rusqlite) directly without spawning wrangler
Selection mechanism: compile-time via cfg(target_arch = "wasm32"), not runtime env var.
The DATABASE_URL env var controls the SQLite file path (default: ./quotesdb.sqlite).
Port note: Native API server binds to localhost:3000 (Trunk UI dev server uses localhost:8080).
Port conflict found and fixed in ticket 00aff0 (was 8080, corrected to 3000).
Updated:
- Ticket 00aff0 (DB abstraction): corrected native server port 8080 → 3000
- Ticket af56a7 (local dev docs): updated title and body to reflect rusqlite approach
- Ticket 9c9546 (new): create
.env.exampledocumentingDATABASE_URL