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#
| Type | Definition | Description |
|---|---|---|
Param | type Param = int | float | str | None | What D1's HTTP API binds: |
Query | type Query = tuple[str, Sequence[Param]] | A statement's SQL and parameters. |
Classes#
Functions#
bind#
bind(value) -> Paramvalue as D1's HTTP API binds it; TypeError for what JSON
cannot carry as a parameter (bytes included: the API binds no
blobs).
| Parameter | Type | Description |
|---|---|---|
value | object |
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__}")