Skip to main content

Module db

Module db 

Source
Expand description

The database, as the request pipeline and the schema-cache loader use it.

Two drivers answer to this interface. sqlx is the one the server and the Lambda adapter run on. A Cloudflare Worker has no sqlx, and speaks the PostgreSQL wire protocol over a socket of its own (issue #50).

The interface is small, and it is shaped by what the callers need rather than by what a driver offers:

  • Rows are decoded to JSON by the driver itself, with no row type in between. An intermediate value per column would be an allocation and a copy on every value of every paged or embedded read.
  • It is used generically, never as dyn, so the native build calls sqlx exactly as it did before the interface existed.
  • Every statement runs inside a transaction (Db::begin). That is where a request’s role and claims are set, and nothing runs outside it.

On wasm32 the futures are not Send, because nothing in a Worker is; see MaybeSend.

Structs§

DbError
A failure reported by a driver.
RawRows
What Tx::fetch_raw reads from a result.
SqlxTx
A transaction on a pooled connection, which goes back to the pool when this is committed or dropped.

Traits§

Db
A database a request can open a transaction on.
MaybeSend
Send natively, nothing at all on wasm32.
MaybeSync
Sync natively, nothing at all on wasm32. See MaybeSend.
Tx
An open transaction. Dropped without Tx::commit, it rolls back.

Type Aliases§

BoxFuture
A boxed future, Send where MaybeSend is. For recursion, which an async fn cannot do without a box.
FetchedThen
What Tx::fetch_json_then returns: the rows, and the second statement’s rows, by position.