GitHub

API reference for api.

D1's HTTP API, as D1Client uses it: POST .../query (rows as objects) and POST .../raw (rows as arrays), each with one statement ({"sql", "params"}) or a batch ({"batch": [...]}), which D1 runs in one transaction.

Every method is an effect sent with a pyfect HttpClient; interrupting it aborts the request. Failures are a D1ApiError for an answer that reports one and an HttpClientError for a request that got no answer.

Re-exports

Types

TypeDefinitionDescription
Paramtype Param = int | float | str | None

What D1's HTTP API binds: bool is sent as 1 / 0, as the Workers binding stores it.

Querytype Query = tuple[str, Sequence[Param]]

A statement's SQL and parameters.

Classes

Functions

bind

bind(value) -> Param

value as D1's HTTP API binds it; TypeError for what JSON cannot carry as a parameter (bytes included: the API binds no blobs).

ParameterTypeDescription
valueobject

Returns Param

def bind(value: object) -> Param:
    """``value`` as D1's HTTP API binds it; ``TypeError`` for what JSON
    cannot carry as a parameter (``bytes`` included: the API binds no
    blobs)."""
    if isinstance(value, bool):
        return int(value)
    if value is None or isinstance(value, (int, float, str)):
        return value
    raise TypeError(f"D1's HTTP API cannot bind a value of type {type(value).__name__}")