Skip to main content

Value

Enum Value 

Source
#[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§

Source§

impl Value

Source

pub fn custom<T>(value: Option<T>) -> Value
where T: for<'q> Encode<'q, Postgres> + Type<Postgres> + Clone + Debug + Send + Sync + 'static,

Wrap any value sqlx can encode for PostgreSQL. None binds a NULL of T’s SQL type.

Source

pub fn is_null(&self) -> bool

true if this value is a (typed) SQL NULL.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<&DateTime<Utc>> for Value

Source§

fn from(v: &DateTime<Utc>) -> Value

Converts to this type from the input type.
Source§

impl<T> From<&Json<T>> for Value
where T: Serialize,

Available on crate feature json only.
Source§

fn from(v: &Json<T>) -> Value

Converts to this type from the input type.
Source§

impl From<&NaiveDate> for Value

Source§

fn from(v: &NaiveDate) -> Value

Converts to this type from the input type.
Source§

impl From<&NaiveDateTime> for Value

Source§

fn from(v: &NaiveDateTime) -> Value

Converts to this type from the input type.
Source§

impl From<&NaiveTime> for Value

Source§

fn from(v: &NaiveTime) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<DateTime<Utc>>> for Value

Source§

fn from(v: &Option<DateTime<Utc>>) -> Value

Converts to this type from the input type.
Source§

impl<T> From<&Option<Json<T>>> for Value
where T: Serialize,

Available on crate feature json only.
Source§

fn from(v: &Option<Json<T>>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<NaiveDate>> for Value

Source§

fn from(v: &Option<NaiveDate>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<NaiveDateTime>> for Value

Source§

fn from(v: &Option<NaiveDateTime>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<NaiveTime>> for Value

Source§

fn from(v: &Option<NaiveTime>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<String>> for Value

Source§

fn from(v: &Option<String>) -> Value

Converts to this type from the input type.
Source§

impl<T> From<&Option<T>> for Value
where T: CustomType,

Source§

fn from(v: &Option<T>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<Uuid>> for Value

Source§

fn from(v: &Option<Uuid>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<Value>> for Value

Source§

fn from(v: &Option<Value>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<Vec<u8>>> for Value

Source§

fn from(v: &Option<Vec<u8>>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<bool>> for Value

Source§

fn from(v: &Option<bool>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<f32>> for Value

Source§

fn from(v: &Option<f32>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<f64>> for Value

Source§

fn from(v: &Option<f64>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<i16>> for Value

Source§

fn from(v: &Option<i16>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<i32>> for Value

Source§

fn from(v: &Option<i32>) -> Value

Converts to this type from the input type.
Source§

impl From<&Option<i64>> for Value

Source§

fn from(v: &Option<i64>) -> Value

Converts to this type from the input type.
Source§

impl From<&String> for Value

Source§

fn from(v: &String) -> Value

Converts to this type from the input type.
Source§

impl From<&Uuid> for Value

Source§

fn from(v: &Uuid) -> Value

Converts to this type from the input type.
Source§

impl From<&Value> for Value

Source§

fn from(v: &Value) -> Value

Converts to this type from the input type.
Source§

impl From<&Vec<DateTime<Utc>>> for Value

Source§

fn from(v: &Vec<DateTime<Utc>>) -> Value

Converts to this type from the input type.
Source§

impl From<&Vec<NaiveDate>> for Value

Source§

fn from(v: &Vec<NaiveDate>) -> Value

Converts to this type from the input type.
Source§

impl From<&Vec<String>> for Value

Source§

fn from(v: &Vec<String>) -> Value

Converts to this type from the input type.
Source§

impl From<&Vec<Uuid>> for Value

Source§

fn from(v: &Vec<Uuid>) -> Value

Converts to this type from the input type.
Source§

impl From<&Vec<bool>> for Value

Source§

fn from(v: &Vec<bool>) -> Value

Converts to this type from the input type.
Source§

impl From<&Vec<f32>> for Value

Source§

fn from(v: &Vec<f32>) -> Value

Converts to this type from the input type.
Source§

impl From<&Vec<f64>> for Value

Source§

fn from(v: &Vec<f64>) -> Value

Converts to this type from the input type.
Source§

impl From<&Vec<i16>> for Value

Source§

fn from(v: &Vec<i16>) -> Value

Converts to this type from the input type.
Source§

impl From<&Vec<i32>> for Value

Source§

fn from(v: &Vec<i32>) -> Value

Converts to this type from the input type.
Source§

impl From<&Vec<i64>> for Value

Source§

fn from(v: &Vec<i64>) -> Value

Converts to this type from the input type.
Source§

impl From<&Vec<u8>> for Value

Source§

fn from(v: &Vec<u8>) -> Value

Converts to this type from the input type.
Source§

impl From<&[DateTime<Utc>]> for Value

Source§

fn from(v: &[DateTime<Utc>]) -> Value

Converts to this type from the input type.
Source§

impl From<&[NaiveDate]> for Value

Source§

fn from(v: &[NaiveDate]) -> Value

Converts to this type from the input type.
Source§

impl From<&[String]> for Value

Source§

fn from(v: &[String]) -> Value

Converts to this type from the input type.
Source§

impl From<&[Uuid]> for Value

Source§

fn from(v: &[Uuid]) -> Value

Converts to this type from the input type.
Source§

impl From<&[bool]> for Value

Source§

fn from(v: &[bool]) -> Value

Converts to this type from the input type.
Source§

impl From<&[f32]> for Value

Source§

fn from(v: &[f32]) -> Value

Converts to this type from the input type.
Source§

impl From<&[f64]> for Value

Source§

fn from(v: &[f64]) -> Value

Converts to this type from the input type.
Source§

impl From<&[i16]> for Value

Source§

fn from(v: &[i16]) -> Value

Converts to this type from the input type.
Source§

impl From<&[i32]> for Value

Source§

fn from(v: &[i32]) -> Value

Converts to this type from the input type.
Source§

impl From<&[i64]> for Value

Source§

fn from(v: &[i64]) -> Value

Converts to this type from the input type.
Source§

impl From<&[u8]> for Value

Source§

fn from(v: &[u8]) -> Value

Converts to this type from the input type.
Source§

impl From<&bool> for Value

Source§

fn from(v: &bool) -> Value

Converts to this type from the input type.
Source§

impl From<&f32> for Value

Source§

fn from(v: &f32) -> Value

Converts to this type from the input type.
Source§

impl From<&f64> for Value

Source§

fn from(v: &f64) -> Value

Converts to this type from the input type.
Source§

impl From<&i16> for Value

Source§

fn from(v: &i16) -> Value

Converts to this type from the input type.
Source§

impl From<&i32> for Value

Source§

fn from(v: &i32) -> Value

Converts to this type from the input type.
Source§

impl From<&i64> for Value

Source§

fn from(v: &i64) -> Value

Converts to this type from the input type.
Source§

impl From<&str> for Value

Source§

fn from(v: &str) -> Value

Converts to this type from the input type.
Source§

impl From<DateTime<Utc>> for Value

Source§

fn from(v: DateTime<Utc>) -> Value

Converts to this type from the input type.
Source§

impl<T> From<Json<T>> for Value
where T: Serialize,

Available on crate feature json only.
Source§

fn from(v: Json<T>) -> Value

Converts to this type from the input type.
Source§

impl From<NaiveDate> for Value

Source§

fn from(v: NaiveDate) -> Value

Converts to this type from the input type.
Source§

impl From<NaiveDateTime> for Value

Source§

fn from(v: NaiveDateTime) -> Value

Converts to this type from the input type.
Source§

impl From<NaiveTime> for Value

Source§

fn from(v: NaiveTime) -> Value

Converts to this type from the input type.
Source§

impl From<Option<&str>> for Value

Source§

fn from(v: Option<&str>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<DateTime<Utc>>> for Value

Source§

fn from(v: Option<DateTime<Utc>>) -> Value

Converts to this type from the input type.
Source§

impl<T> From<Option<Json<T>>> for Value
where T: Serialize,

Available on crate feature json only.
Source§

fn from(v: Option<Json<T>>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<NaiveDate>> for Value

Source§

fn from(v: Option<NaiveDate>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<NaiveDateTime>> for Value

Source§

fn from(v: Option<NaiveDateTime>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<NaiveTime>> for Value

Source§

fn from(v: Option<NaiveTime>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<String>> for Value

Source§

fn from(v: Option<String>) -> Value

Converts to this type from the input type.
Source§

impl<T> From<Option<T>> for Value
where T: CustomType,

Source§

fn from(v: Option<T>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<Uuid>> for Value

Source§

fn from(v: Option<Uuid>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<Value>> for Value

Source§

fn from(v: Option<Value>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<Vec<u8>>> for Value

Source§

fn from(v: Option<Vec<u8>>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<bool>> for Value

Source§

fn from(v: Option<bool>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<f32>> for Value

Source§

fn from(v: Option<f32>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<f64>> for Value

Source§

fn from(v: Option<f64>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<i16>> for Value

Source§

fn from(v: Option<i16>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<i32>> for Value

Source§

fn from(v: Option<i32>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<i64>> for Value

Source§

fn from(v: Option<i64>) -> Value

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(v: String) -> Value

Converts to this type from the input type.
Source§

impl From<Uuid> for Value

Source§

fn from(v: Uuid) -> Value

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(v: Value) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<DateTime<Utc>>> for Value

Source§

fn from(v: Vec<DateTime<Utc>>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<NaiveDate>> for Value

Source§

fn from(v: Vec<NaiveDate>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<String>> for Value

Source§

fn from(v: Vec<String>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<Uuid>> for Value

Source§

fn from(v: Vec<Uuid>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<bool>> for Value

Source§

fn from(v: Vec<bool>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<f32>> for Value

Source§

fn from(v: Vec<f32>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<f64>> for Value

Source§

fn from(v: Vec<f64>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<i16>> for Value

Source§

fn from(v: Vec<i16>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<i32>> for Value

Source§

fn from(v: Vec<i32>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<i64>> for Value

Source§

fn from(v: Vec<i64>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

fn from(v: Vec<u8>) -> Value

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(v: bool) -> Value

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(v: f32) -> Value

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(v: f64) -> Value

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(v: i8) -> Value

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(v: i16) -> Value

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(v: i32) -> Value

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(v: i64) -> Value

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(v: u8) -> Value

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(v: u16) -> Value

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(v: u32) -> Value

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<M> InScope<(M, ()), Here> for M

Source§

impl<M, Rest, N> InScope<(M, (Rest, N)), Last> for N

Source§

impl<X, M, Rest, N, I> InScope<(M, (Rest, N)), There<I>> for X
where X: InScope<(M, Rest), I>,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> IntoKey for T
where T: Into<Value>,

Source§

fn into_key(self) -> Vec<Value>

The key’s values, in primary-key column order.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more