Sign in

    jaredzhou/moonpg/value does not have a README file

    FromValue

    pub(open) trait FromValue {
    fn from_value(Value) -> Self raise ValueError
    }

    Types that can be decoded from a Value.

    Implementations should be strict: raise ValueError when the Value variant doesn't match the expected type.

    impl FromValue for MyType with fn from_value(v : Value) -> MyType raise ValueError {
    match v {
    Value::String(s) => parse_my_type(s)
    _ => raise ValueError::ValueError("expected Value::String, got ...")
    }
    }
    impl FromValue for Bool
    impl FromValue for Int
    impl FromValue for Int64
    impl FromValue for Double
    impl FromValue for String
    impl FromValue for Option[T]
    impl FromValue for Bytes
    impl FromValue for Json

    ToValue

    pub(open) trait ToValue {
    fn to_value(Self) -> Value
    }

    Types that can be converted to a Value for use as SQL parameters.

    impl ToValue for MyType with fn to_value(self) -> Value {
    ...
    }

    let val = my_val.to_value()
    impl ToValue for Bool
    impl ToValue for Int
    impl ToValue for Int64
    impl ToValue for Double
    impl ToValue for String
    impl ToValue for Option[T]
    impl ToValue for Bytes
    impl ToValue for Json
    impl ToValue for UUID

    ValueError

    pub(all) suberror ValueError {
    ValueError(String)
    } derive(
    Debug
    )

    Value conversion error.

    Format

    pub(all) enum Format {
    Text
    Binary
    } derive(Eq,
    Debug
    )

    Data format for a PostgreSQL cell or parameter.

    Text (format code 0) — human-readable representation. Binary (format code 1) — compact wire-protocol representation.

    Timestamp

    pub(all) struct Timestamp(Int64) derive(Eq,
    Debug
    )

    Microseconds since Unix epoch (1970-01-01 00:00:00 UTC).

    Value

    pub(all) enum Value {
    Null
    Bool(Bool)
    Int(Int)
    Int64(Int64)
    Float(Double)
    String(String)
    Bytes(Bytes)
    Timestamp(Int64)
    Json(Json)
    } derive(Eq,
    Debug
    )

    PostgreSQL value type used for encoding (client → server via ToValue) and decoding (server → client via FromValue).

    Variants map to PostgreSQL types as follows:

    VariantPG types
    NullSQL NULL
    Boolbool (16)
    Intint2 (21), int4 (23)
    Int64int8 (20)
    Floatfloat4 (700), float8 (701)
    Stringtext, varchar, bpchar, name, uuid, …
    Bytesbytea (17)
    Timestamp(Int64)timestamp (1114), timestamptz (1184)
    Json(Json)json (114), jsonb (3802)

    Source Files