#[non_exhaustive]pub enum Value {
Show 15 variants
Bool(Option<bool>),
I16(Option<i16>),
I32(Option<i32>),
I64(Option<i64>),
F32(Option<f32>),
F64(Option<f64>),
String(Option<String>),
Bytes(Option<Vec<u8>>),
Uuid(Option<Uuid>),
DateTime(Option<DateTime<Utc>>),
NaiveDateTime(Option<NaiveDateTime>),
NaiveDate(Option<NaiveDate>),
NaiveTime(Option<NaiveTime>),
Json(Option<Value>),
Custom(CustomValue),
}Expand description
A dynamically typed, bindable SQL value.
Every variant carries an Option so that NULLs keep their SQL type,
which PostgreSQL requires when binding parameters.
You rarely build a Value yourself: anything implementing Into<Value>
(integers, floats, strings, bool, Vec<u8>, their Options and, with
the matching features, chrono, uuid and JSON types) can be passed to
the query builder directly.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Bool(Option<bool>)
BOOLEAN
I16(Option<i16>)
SMALLINT (INT2)
I32(Option<i32>)
INTEGER (INT4)
I64(Option<i64>)
BIGINT (INT8)
F32(Option<f32>)
REAL (FLOAT4)
F64(Option<f64>)
DOUBLE PRECISION (FLOAT8)
String(Option<String>)
TEXT / VARCHAR
Bytes(Option<Vec<u8>>)
BYTEA
Uuid(Option<Uuid>)
UUID
DateTime(Option<DateTime<Utc>>)
TIMESTAMPTZ
NaiveDateTime(Option<NaiveDateTime>)
TIMESTAMP
NaiveDate(Option<NaiveDate>)
DATE
NaiveTime(Option<NaiveTime>)
TIME
Json(Option<Value>)
JSONB / JSON
Custom(CustomValue)
Any other type sqlx can encode: enums and newtypes from
#[derive(DbEnum)] / #[derive(DbNewtype)], or types registered
with impl_value!. Build one with Value::custom.
Implementations§
Trait Implementations§
Source§impl From<&NaiveDateTime> for Value
impl From<&NaiveDateTime> for Value
Source§fn from(v: &NaiveDateTime) -> Value
fn from(v: &NaiveDateTime) -> Value
Converts to this type from the input type.
Source§impl<T> From<&Option<Json<T>>> for Valuewhere
T: Serialize,
Available on crate feature json only.
impl<T> From<&Option<Json<T>>> for Valuewhere
T: Serialize,
Available on crate feature
json only.Source§impl From<NaiveDateTime> for Value
impl From<NaiveDateTime> for Value
Source§fn from(v: NaiveDateTime) -> Value
fn from(v: NaiveDateTime) -> Value
Converts to this type from the input type.
Source§impl<T> From<Option<Json<T>>> for Valuewhere
T: Serialize,
Available on crate feature json only.
impl<T> From<Option<Json<T>>> for Valuewhere
T: Serialize,
Available on crate feature
json only.impl StructuralPartialEq for Value
Auto Trait Implementations§
impl !RefUnwindSafe for Value
impl !UnwindSafe for Value
impl Freeze for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnsafeUnpin for Value
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<M> InScope<(M, ()), Here> for M
impl<M, Rest, N> InScope<(M, (Rest, N)), Last> for N
impl<X, M, Rest, N, I> InScope<(M, (Rest, N)), There<I>> for X
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more