Expand description
Cloudflare D1 adapter for the ruprizzle ORM.
D1Pool implements ruprizzle::Executor against a D1 database through the
Cloudflare REST API: each statement is one
POST /accounts/{account}/d1/database/{database}/query, authenticated with an
API token.
§What this adapter does and does not do
This is the adapter for code that talks to D1 from outside a Worker — a CLI, a migration job, a server. Inside a Worker you have a D1 binding, which is faster and needs no token; this crate does not use bindings.
Every statement is one HTTP request, so there is no interactive transaction:
BEGIN and COMMIT sent separately would not share a connection and are not
supported. D1’s HTTP interface also takes no binary parameter, so ruprizzle
Bytes values are refused rather than mangled — store them encoded in a text
column. The same goes for a non-finite F64 (NaN, ±inf): JSON has no form
for it, and before 1.5.2 it was sent as null and stored as NULL.
Parameters and results cross the API as JSON numbers, which D1’s JavaScript runtime holds as doubles. An integer beyond ±2^53 (9 007 199 254 740 992) is therefore rounded by D1 itself, on the way in and on the way out, before this adapter sees it. Store such values (64-bit IDs, snowflakes) as text.
§Example
use ruprizzle::Executor;
use ruprizzle::value::Value;
use ruprizzle_d1::D1Pool;
let pool = D1Pool::builder()
.account_id(std::env::var("CLOUDFLARE_ACCOUNT_ID")?)
.database_id(std::env::var("D1_DATABASE_ID")?)
.api_token(std::env::var("CLOUDFLARE_API_TOKEN")?)
.build()?;
let rows = pool
.fetch_all_raw("SELECT id, email FROM users WHERE id = ?".into(), vec![Value::I64(7)])
.await?;Structs§
- D1Pool
- A handle to a Cloudflare D1 database over the REST API.
- D1Pool
Builder - Builder for
D1Pool.
Enums§
- D1Error
- Errors raised by the D1 adapter.