pub enum Value {
}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
impl Value
Sourcepub fn from_u64_clamped(v: u64) -> Self
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));Sourcepub fn to_f32_lossy(&self) -> Result<f32>
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());Sourcepub fn to_f64_lossy(&self) -> Result<f64>
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<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl FromValue for Value
impl FromValue for Value
Source§fn from_value(value: &Value) -> Result<Self>
fn from_value(value: &Value) -> Result<Self>
Source§impl<T> TryFrom<Value> for Option<T>
TryFrom for Option<T> - returns None for Null, tries to convert otherwise
impl<T> TryFrom<Value> for Option<T>
TryFrom for Option<T> - returns None for Null, tries to convert otherwise
Source§impl TryFrom<u64> for Value
Convert a u64 to Value, returning an error if the value exceeds i64::MAX.
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.