2.4 KiB
+++ title = "[TRIAGE] SQLx + workers-rs + Cloudflare D1 compatibility (known issues?)" priority = 9 status = "done" ticket_type = "task" dependencies = [] +++
This is a triage decision ticket. It must be resolved before dependent implementation tickets can proceed. SQLx + workers-rs + Cloudflare D1 compatibility: does SQLx work with the Cloudflare D1 driver in a workers-rs environment? D1 uses a non-standard connection protocol. 1. **SQLx with libsql (Turso)** — Turso provides a SQLx-compatible driver. Use for local dev; switch to D1 in production via a different connection string. 2. **workers-rs D1 bindings** — workers-rs provides native D1 bindings that bypass SQLx. Requires rewriting DB access without SQLx macros. 3. **SQLite over HTTP (Turso)** — use Turso in both dev and production (Turso cloud instead of D1). Avoids D1 entirely. **Option 2: workers-rs D1 bindings, extended with a `cfg(target_arch)`-based native path.**SQLx is fundamentally incompatible with Cloudflare Workers/D1. D1 is accessed through the
workers-rs JavaScript binding layer (worker::d1::D1Database), not a TCP connection.
SQLx requires a TCP-based connection and its compile-time query macros cannot run in the
Workers/WASM build environment.
Chosen architecture:
#[cfg(target_arch = "wasm32")]→ workers-rsD1Databasebindings (production)#[cfg(not(target_arch = "wasm32"))]→rusqlite+tokio-rusqlite(native dev/tests)
A QuoteRepository async trait provides a unified interface. Concrete type aliases
(AppRepo) avoid trait-object Send/Sync constraints in Axum handlers.
cargo test on the native host automatically selects the rusqlite path — no wrangler dev
or feature flags needed for integration tests.
The design doc's "Query layer: SQLx" is superseded. See implementation ticket 00aff0.
- Implementation ticket created: **00aff0** — full plan for Repository trait + D1/rusqlite impls. - Ticket a5049d (database connection module) updated — SQLx goal superseded. - Ticket 1f5bb5 (Cargo.toml) updated — cfg-split dependency constraints corrected. - Tickets a91260 and 2ab7a8 also resolved by this decision (see those tickets). `chore(quotesdb): resolve triage — sqlx-workersrs-cloudflare-d1-compatibility-known-issues`