Skip to main content

Module value_json

Module value_json 

Source
Expand description

JSON encoding for stmt::Values stored in document-backed columns. JSON encoding for stmt::Values stored in document-backed columns (MySQL JSON, SQLite TEXT via the JSON1 extension, and eventually PostgreSQL jsonb for #[document]-marked fields). The conversion is intentionally a plain pair of functions rather than a Serialize / Deserialize impl on stmt::Value: the encoding is opinionated (UUIDs / decimals / timestamps as JSON strings) and matches the per-column TEXT encoding the same scalar would have at the SQL level. Backends with typed document storage (BSON, DynamoDB) need different representations.

Decoding requires the element type from the schema — Value::Uuid vs Value::String are both JSON strings on the wire, and only the caller’s stmt::Type distinguishes them.

Functions§

value_from_json
Decode a serde_json::Value into a stmt::Value of type ty.
value_list_from_json
Decode a JSON array document into a Value::List, using elem_ty as the per-element type.
value_list_to_json
Encode a Value::List as a JSON array document. The element type drives per-element encoding via value_to_json.
value_to_json
Encode a scalar stmt::Value as a serde_json::Value. Panics on shapes that have no JSON representation (Record, nested List, Bytes, SparseRecord, Null records, NaN / infinity).