Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 16 variants Null, TinyInt(i8), SmallInt(i16), Integer(i32), BigInt(i64), Real(f64), Decimal(i128, u8), Text(String), Bytes(Bytes), Boolean(bool), Date(i32), Time(i64), Timestamp(Timestamp), Uuid([u8; 16]), Json(Value), Placeholder(usize),
}
Expand description

A typed SQL value.

Represents values that can appear in query parameters, row data, and comparison predicates.

Note: Real and Decimal types use total ordering (NaN < -Inf < values < Inf) for comparisons to enable use in B+tree indexes.

Variants§

§

Null

SQL NULL.

§

TinyInt(i8)

8-bit signed integer (-128 to 127).

§

SmallInt(i16)

16-bit signed integer (-32,768 to 32,767).

§

Integer(i32)

32-bit signed integer (-2^31 to 2^31-1).

§

BigInt(i64)

64-bit signed integer (-2^63 to 2^63-1).

§

Real(f64)

64-bit floating point (IEEE 754 double precision).

§

Decimal(i128, u8)

Fixed-precision decimal (value in smallest units, scale).

Stored as (i128, u8) where the second field is the scale. Example: Decimal(12345, 2) represents 123.45

§

Text(String)

UTF-8 text string.

§

Bytes(Bytes)

Raw bytes (base64 encoded in JSON).

§

Boolean(bool)

Boolean value.

§

Date(i32)

Date (days since Unix epoch).

§

Time(i64)

Time of day (nanoseconds within day).

§

Timestamp(Timestamp)

Timestamp (nanoseconds since Unix epoch).

§

Uuid([u8; 16])

UUID (RFC 4122, 128-bit).

§

Json(Value)

JSON document (validated).

§

Placeholder(usize)

Parameter placeholder ($1, $2, etc.) - 1-indexed. This is an intermediate representation used during parsing, and should be bound to actual values before execution.

Implementations§

Source§

impl Value

Source

pub fn data_type(&self) -> Option<DataType>

Returns the data type of this value.

Returns None for Null and Placeholder since they have no concrete type.

Source

pub fn is_null(&self) -> bool

Returns true if this value is NULL.

Source

pub fn as_bigint(&self) -> Option<i64>

Returns the value as an i64, if it is a BigInt.

Source

pub fn as_text(&self) -> Option<&str>

Returns the value as a string slice, if it is Text.

Source

pub fn as_boolean(&self) -> Option<bool>

Returns the value as a bool, if it is Boolean.

Source

pub fn as_timestamp(&self) -> Option<Timestamp>

Returns the value as a Timestamp, if it is Timestamp.

Source

pub fn as_bytes(&self) -> Option<&Bytes>

Returns the value as bytes, if it is Bytes.

Source

pub fn as_tinyint(&self) -> Option<i8>

Returns the value as an i8, if it is a TinyInt.

Source

pub fn as_smallint(&self) -> Option<i16>

Returns the value as an i16, if it is a SmallInt.

Source

pub fn as_integer(&self) -> Option<i32>

Returns the value as an i32, if it is an Integer.

Source

pub fn as_real(&self) -> Option<f64>

Returns the value as an f64, if it is a Real.

Source

pub fn as_decimal(&self) -> Option<(i128, u8)>

Returns the value as a Decimal (value, scale), if it is a Decimal.

Source

pub fn as_uuid(&self) -> Option<&[u8; 16]>

Returns the value as a Uuid, if it is a Uuid.

Source

pub fn as_json(&self) -> Option<&Value>

Returns the value as a Json, if it is a Json.

Source

pub fn as_date(&self) -> Option<i32>

Returns the value as a Date, if it is a Date.

Source

pub fn as_time(&self) -> Option<i64>

Returns the value as a Time, if it is a Time.

Source

pub fn compare(&self, other: &Value) -> Option<Ordering>

Compares two values for ordering.

NULL values are considered less than all non-NULL values. Values of different types return None (incomparable).

For Real values, uses total ordering: NaN < -Inf < values < Inf.

Source

pub fn is_compatible_with(&self, data_type: DataType) -> bool

Checks if this value can be assigned to a column of the given type.

Source

pub fn to_json(&self) -> Value

Converts this value to JSON.

§Panics

Panics if the value is a Placeholder (should be bound before conversion).

Source

pub fn from_json(json: &Value, data_type: DataType) -> Result<Self>

Parses a value from JSON with an expected data type.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · 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

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

impl Default for Value

Source§

fn default() -> Value

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Value

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Value

Source§

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

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

impl From<&str> for Value

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 16]> for Value

Source§

fn from(u: [u8; 16]) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for Value

Source§

fn from(b: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Timestamp> for Value

Source§

fn from(ts: Timestamp) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(j: Value) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(v: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(v: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(v: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(v: i8) -> Self

Converts to this type from the input type.
Source§

impl Hash for Value

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Value

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Value

Auto Trait Implementations§

§

impl !Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe 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<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, 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,