DrinkMeAlice. Ash. Codec
(drink_me_alice v0.1.0)
Copy Markdown
Attribute ↔ SurrealDB value mapping for the Ash data layer, keyed on
Ash.Type.storage_type/2.
| storage type | Surreal field | written as |
|---|---|---|
:string :citext :uuid :binary_id | string | exact string (DrinkMeAlice.exact_string/1) |
:naive_datetime* :date :time* | string | exact ISO-8601 string |
:integer | int | $p (i64) |
:boolean | bool | $p |
:utc_datetime :utc_datetime_usec | datetime | <datetime>$p |
:decimal | decimal | <decimal>$p (decimal string) |
:float | float | <float>$p (float string) |
:map | string | exact canonical JSON text |
{:array, scalar} | array<T> | element-wise as above |
Why: SurrealDB 3.0.5 coerces typed-looking JSON strings — date-shaped
strings become datetimes and do not survive a <string> cast (see
DrinkMeAlice.exact_string/1) — so every string travels in the exact form.
The outbound encoder (DrinkMeAlice.Json.encode/1) carries only
canonical terms, so floats, decimals and datetimes travel as strings
cast in SurrealQL. Maps are stored as canonical JSON text rather than
as objects: an object's nested strings would be coerced, and there is
no server-side JSON parse to undo it; the cost is that map contents
are not filterable. nil is written as the literal NONE: a JSON
null is rejected by option<T> fields.
Anything else is {:error, {:unsupported_type, name, storage}} — at
schema generation and at write time — rather than a lossy guess.
Summary
Functions
Decode one stored field value back into the attribute's Ash value
(nil for an absent field).
Encode one attribute value for a write or a filter comparison:
{:ok, :none} for nil (write the literal NONE), or
{:ok, {kind, wire_value}} — pair with param_sql/2.
The Surreal field type for an attribute, without option<>:
{:ok, "string"} | {:error, {:unsupported_type, name, storage}}.
The SurrealQL expression reading param name of kind back into the
stored value.
The storage type for an attribute.
The wire kind for a storage type, or :error.
Types
Functions
Decode one stored field value back into the attribute's Ash value
(nil for an absent field).
Encode one attribute value for a write or a filter comparison:
{:ok, :none} for nil (write the literal NONE), or
{:ok, {kind, wire_value}} — pair with param_sql/2.
The Surreal field type for an attribute, without option<>:
{:ok, "string"} | {:error, {:unsupported_type, name, storage}}.
The SurrealQL expression reading param name of kind back into the
stored value.
The storage type for an attribute.
The wire kind for a storage type, or :error.