#[non_exhaustive]pub enum Value {
Show 23 variants
Null,
Bool(bool),
I8(i8),
I16(i16),
I32(i32),
I64(i64),
U8(u8),
U16(u16),
U32(u32),
U64(u64),
F32(f32),
F64(f64),
Text(String),
Bytes(Vec<u8>),
Array(Vec<Value>),
Date(NaiveDate),
Time(NaiveTime),
DateTime(NaiveDateTime),
TimestampTz(DateTime<Utc>),
Uuid(Uuid),
Decimal(Decimal),
Json(Value),
Custom(Arc<dyn CustomValue>),
}Expand description
A bound argument.
keelson carries its own value enum rather than being generic over a driver’s
parameter type. That keeps Expression free of any
backend type parameter, and it means a built query’s arguments can be
inspected — printed, compared, serialised — without a database in the loop.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Null
SQL NULL.
Bool(bool)
A boolean.
I8(i8)
An 8-bit signed integer.
I16(i16)
A 16-bit signed integer.
I32(i32)
A 32-bit signed integer.
I64(i64)
A 64-bit signed integer.
U8(u8)
An 8-bit unsigned integer.
U16(u16)
A 16-bit unsigned integer.
U32(u32)
A 32-bit unsigned integer.
U64(u64)
A 64-bit unsigned integer.
F32(f32)
A single-precision float.
F64(f64)
A double-precision float.
Text(String)
Character data.
Bytes(Vec<u8>)
Binary data — BYTEA, BLOB.
Array(Vec<Value>)
A homogeneous array, for dialects that have one (PostgreSQL).
Date(NaiveDate)
A calendar date with no time and no zone — DATE.
Time(NaiveTime)
A wall-clock time with no date and no zone — TIME.
DateTime(NaiveDateTime)
A date and time with no zone — TIMESTAMP / DATETIME. What it means
depends on context the database never sees, which is why it is a
different variant from Value::TimestampTz, not a special case of it.
TimestampTz(DateTime<Utc>)
An instant, carried in UTC — TIMESTAMPTZ.
There is deliberately no offset-preserving variant: every zoned
chrono::DateTime<Tz> is normalised to UTC on conversion, because no
target database round-trips an offset (PostgreSQL’s timestamptz
stores UTC and renders in the session zone; MySQL’s TIMESTAMP
converts through the session zone; SQLite has no zone at all). A
variant that pretended otherwise would promise what no backend keeps.
Uuid(Uuid)
A UUID — uuid on PostgreSQL, hyphenated text elsewhere.
Decimal(Decimal)
An exact decimal number — NUMERIC / DECIMAL. A separate variant
from the floats because binary floating point cannot represent decimal
scale, which is the entire reason an application reaches for Decimal.
Json(Value)
A JSON document — jsonb / JSON, serialised text elsewhere.
Custom(Arc<dyn CustomValue>)
Escape hatch for dialect-specific types. Backends downcast through
CustomValue::as_any.
Implementations§
Source§impl Value
impl Value
Sourcepub fn array<T: ToValue, I: IntoIterator<Item = T>>(items: I) -> Value
pub fn array<T: ToValue, I: IntoIterator<Item = T>>(items: I) -> Value
Build a Value::Array from anything iterable.
There is deliberately no blanket ToValue for Vec<T>: it would collide
with Vec<u8>, which must stay Value::Bytes so BYTEA/BLOB binds
correctly. Arrays are therefore explicit.
Sourcepub fn custom<C: CustomValue>(value: C) -> Value
pub fn custom<C: CustomValue>(value: C) -> Value
Wrap a dialect-specific value.
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Whether this is Value::Null.