Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 19 variants Null, Bool(bool), TinyInt(i8), SmallInt(i16), Int(i32), BigInt(i64), Float(f32), Double(f64), Decimal(String), Text(String), Bytes(Vec<u8>), Date(i32), Time(i64), Timestamp(i64), TimestampTz(i64), Uuid([u8; 16]), Json(Value), Array(Vec<Value>), Default,
}
Expand description

A dynamically-typed SQL value.

This enum represents all possible SQL values and is used for parameter binding and result fetching.

Variants§

§

Null

NULL value

§

Bool(bool)

Boolean value

§

TinyInt(i8)

8-bit signed integer

§

SmallInt(i16)

16-bit signed integer

§

Int(i32)

32-bit signed integer

§

BigInt(i64)

64-bit signed integer

§

Float(f32)

32-bit floating point

§

Double(f64)

64-bit floating point

§

Decimal(String)

Arbitrary precision decimal (stored as string)

§

Text(String)

Text string

§

Bytes(Vec<u8>)

Binary data

§

Date(i32)

Date (days since epoch)

§

Time(i64)

Time (microseconds since midnight)

§

Timestamp(i64)

Timestamp (microseconds since epoch)

§

TimestampTz(i64)

Timestamp with timezone (microseconds since epoch, UTC)

§

Uuid([u8; 16])

UUID (as 16 bytes)

§

Json(Value)

JSON value

§

Array(Vec<Value>)

Array of values

§

Default

SQL DEFAULT keyword

Implementations§

Source§

impl Value

Source

pub const fn is_null(&self) -> bool

Check if this value is NULL.

Source

pub const fn type_name(&self) -> &'static str

Get the type name of this value.

Source

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

Try to convert this value to a bool.

Source

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

Try to convert this value to an i64.

Source

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

Try to convert this value to an f64.

Source

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

Try to get this value as a string reference.

Source

pub fn as_bytes(&self) -> Option<&[u8]>

Try to get this value as a byte slice.

Source

pub fn from_u64_clamped(v: u64) -> Self

Convert a u64 to Value, clamping to i64::MAX if it overflows.

This is a convenience method for cases where you want to store large u64 values as the largest representable signed integer rather than erroring. A warning is logged when clamping occurs.

For strict conversion that errors on overflow, use Value::try_from(u64).

§Examples
use sqlmodel_core::Value;

// Small values convert normally
assert_eq!(Value::from_u64_clamped(42), Value::BigInt(42));

// Large values are clamped to i64::MAX
assert_eq!(Value::from_u64_clamped(u64::MAX), Value::BigInt(i64::MAX));
Source

pub fn to_f32_lossy(&self) -> Result<f32>

Convert to f32, allowing precision loss for large values.

This is more lenient than TryFrom<Value> for f32, which errors on precision loss. Only returns an error for values that cannot be represented at all (infinity, NaN).

§Examples
use sqlmodel_core::Value;

// Normal values work
assert!(Value::Double(1.5).to_f32_lossy().is_ok());

// Large integers are converted with precision loss (no error)
assert!(Value::BigInt(i64::MAX).to_f32_lossy().is_ok());
Source

pub fn to_f64_lossy(&self) -> Result<f64>

Convert to f64, allowing precision loss for very large integers.

This is more lenient than TryFrom<Value> for f64, which errors on precision loss. Only returns an error for non-numeric values.

§Examples
use sqlmodel_core::Value;

// Normal values work
assert!(Value::BigInt(42).to_f64_lossy().is_ok());

// Large integers are converted with precision loss (no error)
assert!(Value::BigInt(i64::MAX).to_f64_lossy().is_ok());

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<'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 From<&[u8]> for Value

Source§

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

Converts to this type from the input type.
Source§

impl<T: Clone + Into<Value>> From<&Hybrid<T>> for Value

Source§

fn from(h: &Hybrid<T>) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Value

Source§

fn from(v: &str) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 16]> for Value

Source§

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

Converts to this type from the input type.
Source§

impl<T: Into<Value>> From<Hybrid<T>> for Value

Source§

fn from(h: Hybrid<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value>> From<Option<T>> for Value

Source§

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

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(v: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(v: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<String>> for Value

Convert a Vec<String> into a Value::Array.

Source§

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

Converts to this type from the input type.
Source§

impl From<Vec<bool>> for Value

Convert a Vec<bool> into a Value::Array.

Source§

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

Converts to this type from the input type.
Source§

impl From<Vec<f64>> for Value

Convert a Vec<f64> into a Value::Array.

Source§

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

Converts to this type from the input type.
Source§

impl From<Vec<i32>> for Value

Convert a Vec<i32> into a Value::Array.

Source§

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

Converts to this type from the input type.
Source§

impl From<Vec<i64>> for Value

Convert a Vec<i64> into a Value::Array.

Source§

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

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

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

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(v: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(v: f32) -> 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 From<u16> for Value

Source§

fn from(v: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(v: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(v: u8) -> Self

Converts to this type from the input type.
Source§

impl FromValue for Value

Source§

fn from_value(value: &Value) -> Result<Self>

Convert from a Value, returning an error if the conversion fails.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> 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 TryFrom<Value> for [u8; 16]

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T> TryFrom<Value> for Option<T>
where T: TryFrom<Value, Error = Error>,

TryFrom for Option<T> - returns None for Null, tries to convert otherwise

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for String

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Value

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Vec<String>

TryFrom for Vec<String> - extracts text array.

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Vec<bool>

TryFrom for Vec<bool> - extracts boolean array.

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Vec<f64>

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Vec<i32>

TryFrom for Vec<i32> - extracts integer array.

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Vec<i64>

TryFrom for Vec<i64> - extracts bigint array.

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Vec<u8>

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for bool

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for f32

Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Convert a Value to f32, returning an error if precision would be lost.

For lossy conversion (accepting precision loss), use Value::to_f32_lossy().

Source§

type Error = Error

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

impl TryFrom<Value> for f64

Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Convert a Value to f64, returning an error if precision would be lost.

For lossy conversion (accepting precision loss), use Value::to_f64_lossy().

Source§

type Error = Error

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

impl TryFrom<Value> for i16

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for i32

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for i64

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for i8

Source§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u64> for Value

Convert a u64 to Value, returning an error if the value exceeds i64::MAX.

SQL BIGINT is signed, so values larger than i64::MAX cannot be stored directly. Use Value::from_u64_clamped() if you want silent clamping instead of an error.

Source§

type Error = Error

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

fn try_from(v: u64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq 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> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
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> ModelDump for T
where T: Serialize,

Source§

fn model_dump(&self, options: DumpOptions) -> Result<Value, Error>

Serialize a model to a JSON value. Read more
Source§

fn model_dump_json(&self) -> Result<String, Error>

Serialize a model to a JSON string with default options.
Source§

fn model_dump_json_pretty(&self) -> Result<String, Error>

Serialize a model to a pretty-printed JSON string.
Source§

fn model_dump_json_with_options( &self, options: DumpOptions, ) -> Result<String, Error>

Serialize a model to a JSON string with full options support. Read more
Source§

impl<T> ModelValidate for T

Source§

fn model_validate( input: impl Into<ValidateInput>, options: ValidateOptions, ) -> Result<T, ValidationError>

Create and validate a model from input. Read more
Source§

fn model_validate_json(json: &str) -> ValidateResult<Self>

Create and validate a model from JSON string with default options.
Source§

fn model_validate_dict(dict: HashMap<String, Value>) -> ValidateResult<Self>

Create and validate a model from a HashMap with default options.
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, 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<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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,