postgleam/decode
Types
A decoder that extracts a typed value from a row (list of columns).
pub opaque type RowDecoder(a)
A decoder that extracts a typed value from a single cell.
pub type ValueDecoder(a) =
fn(option.Option(value.Value)) -> Result(a, error.Error)
Values
pub fn bit_string(
val: option.Option(value.Value),
) -> Result(#(Int, BitArray), error.Error)
Decode a bit/varbit value as #(bit_count, data).
pub fn bool(
val: option.Option(value.Value),
) -> Result(Bool, error.Error)
Decode a boolean value.
pub fn box(
val: option.Option(value.Value),
) -> Result(#(Float, Float, Float, Float), error.Error)
Decode a box as #(x1, y1, x2, y2) (upper-right, lower-left).
pub fn bytea(
val: option.Option(value.Value),
) -> Result(BitArray, error.Error)
Decode a bytea (binary data) value.
pub fn circle(
val: option.Option(value.Value),
) -> Result(#(Float, Float, Float), error.Error)
Decode a circle as #(x, y, radius).
pub fn date(
val: option.Option(value.Value),
) -> Result(Int, error.Error)
Decode a date value (days since 2000-01-01).
pub fn element(
index: Int,
decoder: fn(option.Option(value.Value)) -> Result(
a,
error.Error,
),
next: fn(a) -> RowDecoder(b),
) -> RowDecoder(b)
Decode the element at a given column index using a value decoder.
Designed for use with Gleam’s use syntax.
let decoder = {
use id <- decode.element(0, decode.int)
use name <- decode.element(1, decode.text)
decode.success(#(id, name))
}
pub fn float(
val: option.Option(value.Value),
) -> Result(Float, error.Error)
Decode a float value (float4, float8).
pub fn inet(
val: option.Option(value.Value),
) -> Result(#(Int, BitArray, Int), error.Error)
Decode an inet/cidr value as #(family, address, netmask).
pub fn int(
val: option.Option(value.Value),
) -> Result(Int, error.Error)
Decode an integer value (int2, int4, int8).
pub fn interval(
val: option.Option(value.Value),
) -> Result(#(Int, Int, Int), error.Error)
Decode an interval value as #(microseconds, days, months).
pub fn json(
val: option.Option(value.Value),
) -> Result(String, error.Error)
Decode a JSON value (string).
pub fn jsonb(
val: option.Option(value.Value),
) -> Result(String, error.Error)
Decode a JSONB value (string).
pub fn jsonpath(
val: option.Option(value.Value),
) -> Result(String, error.Error)
Decode a JSONPath value (string).
pub fn line(
val: option.Option(value.Value),
) -> Result(#(Float, Float, Float), error.Error)
Decode a line value as #(a, b, c) coefficients.
pub fn lseg(
val: option.Option(value.Value),
) -> Result(#(Float, Float, Float, Float), error.Error)
Decode a line segment as #(x1, y1, x2, y2).
pub fn macaddr(
val: option.Option(value.Value),
) -> Result(BitArray, error.Error)
Decode a macaddr value (6-byte binary).
pub fn macaddr8(
val: option.Option(value.Value),
) -> Result(BitArray, error.Error)
Decode a macaddr8 value (8-byte binary).
pub fn money(
val: option.Option(value.Value),
) -> Result(Int, error.Error)
Decode a money value (int64 cents).
pub fn numeric(
val: option.Option(value.Value),
) -> Result(String, error.Error)
Decode a numeric/decimal value (string representation).
pub fn optional(
decoder: fn(option.Option(value.Value)) -> Result(
a,
error.Error,
),
) -> fn(option.Option(value.Value)) -> Result(
option.Option(a),
error.Error,
)
Make any value decoder nullable (NULL-safe).
Returns Ok(None) for NULL, Ok(Some(val)) for non-NULL.
pub fn path(
val: option.Option(value.Value),
) -> Result(#(Bool, List(#(Float, Float))), error.Error)
Decode a path as #(closed, points).
pub fn point(
val: option.Option(value.Value),
) -> Result(#(Float, Float), error.Error)
Decode a point value as #(x, y).
pub fn polygon(
val: option.Option(value.Value),
) -> Result(List(#(Float, Float)), error.Error)
Decode a polygon as a list of vertices.
pub fn run(
decoder: RowDecoder(a),
row: List(option.Option(value.Value)),
) -> Result(a, error.Error)
Run a decoder on a row.
pub fn text(
val: option.Option(value.Value),
) -> Result(String, error.Error)
Decode a text/string value.
pub fn time(
val: option.Option(value.Value),
) -> Result(Int, error.Error)
Decode a time value (microseconds since midnight).
pub fn timestamp(
val: option.Option(value.Value),
) -> Result(Int, error.Error)
Decode a timestamp value (microseconds since 2000-01-01 00:00:00).
pub fn timestamptz(
val: option.Option(value.Value),
) -> Result(Int, error.Error)
Decode a timestamptz value (microseconds since 2000-01-01 00:00:00 UTC).
pub fn timetz(
val: option.Option(value.Value),
) -> Result(#(Int, Int), error.Error)
Decode a timetz value as #(microseconds, tz_offset_seconds).
pub fn uuid(
val: option.Option(value.Value),
) -> Result(BitArray, error.Error)
Decode a UUID value (16-byte binary).
pub fn uuid_string(
val: option.Option(value.Value),
) -> Result(String, error.Error)
Decode a UUID value as a hyphenated string (e.g. “550e8400-e29b-41d4-a716-446655440000”).
pub fn xml(
val: option.Option(value.Value),
) -> Result(String, error.Error)
Decode an XML value (string).