sqlx drivers for Cloudflare Workers: real
sqlx::Databaseimplementations, so code written against sqlx's runtime API runs inside a Rust Worker.
Note
Pre-1.0. The API may still change between minor versions.
| Crate | Version | Docs | What it is |
|---|---|---|---|
sqlx-cloudflare-d1 |
A driver for Cloudflare D1, over the Workers D1 binding | ||
sqlx-cloudflare-do |
A driver for a Durable Object's SQL storage | ||
sqlx-cloudflare-core |
The internals both drivers share -- not a dependency of yours |
Each driver is independent: depend on the one for the storage you use. Both
are SQLite behind a JavaScript API, so they share their value model, type
mapping and error parsing through sqlx-cloudflare-core.
- D1 is one database your Worker talks to over the network: shared by
every request, queryable across all your data, managed with
wrangler d1. Atomic work goes through a batch -- D1 has no interactive transactions. - Durable Object storage is a private SQLite database inside each object, in the same process as your code: queries take microseconds, every request to an object sees one consistent database, and transactions are real. Pick it for per-user, per-tenant or per-room data.
Both drivers map types the same way and share the same limit on integers (±2^53 − 1, since values cross as JavaScript numbers).
Everything runs inside the dev shell -- nix develop, or the Dev Container:
make check # host and wasm32-unknown-unknown
make lint
make test
make test-worker # the integration tests, under `wrangler dev --local`