Skip to main content

SqliteValue

Enum SqliteValue 

Source
pub enum SqliteValue {
    Null,
    Integer(i64),
    Float(f64),
    Text(String),
    Blob(Vec<u8>),
}
Expand description

A dynamically-typed SQLite value.

Corresponds to C SQLite’s sqlite3_value / Mem type. SQLite has five fundamental storage classes: NULL, INTEGER, REAL, TEXT, and BLOB.

Variants§

§

Null

SQL NULL.

§

Integer(i64)

A 64-bit signed integer.

§

Float(f64)

A 64-bit IEEE 754 floating-point number.

§

Text(String)

A UTF-8 text string.

§

Blob(Vec<u8>)

A binary large object.

Implementations§

Source§

impl SqliteValue

Source

pub const fn affinity(&self) -> TypeAffinity

Returns the type affinity that best describes this value.

Source

pub const fn storage_class(&self) -> StorageClass

Returns the storage class of this value.

Source

pub fn apply_affinity(self, affinity: TypeAffinity) -> Self

Apply column type affinity coercion (advisory mode).

In non-STRICT tables, affinity is advisory: values are coerced when possible but never rejected. Follows SQLite §3.4 rules from https://www.sqlite.org/datatype3.html#type_affinity_of_a_column.

  • TEXT affinity: numeric values converted to text before storing.
  • NUMERIC affinity: text parsed as integer/real if well-formed.
  • INTEGER affinity: like NUMERIC, plus exact-integer reals become integer.
  • REAL affinity: like NUMERIC, plus integers forced to float.
  • BLOB affinity: no conversion.
Source

pub fn validate_strict( self, col_type: StrictColumnType, ) -> Result<Self, StrictTypeError>

Validate a value against a STRICT table column type.

NULL is always accepted (nullability is enforced separately via NOT NULL). Returns Ok(value) with possible implicit coercion (REAL columns accept integers, converting them to float), or Err if the storage class is incompatible.

Source

pub const fn is_null(&self) -> bool

Returns true if this is a NULL value.

Source

pub const fn as_integer(&self) -> Option<i64>

Try to extract an integer value.

Source

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

Try to extract a float value.

Source

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

Try to extract a text reference.

Source

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

Try to extract a blob reference.

Source

pub fn to_integer(&self) -> i64

Convert to an integer following SQLite’s type coercion rules.

  • NULL -> 0
  • Integer -> itself
  • Float -> truncated to i64
  • Text -> attempt to parse, 0 on failure
  • Blob -> 0
Source

pub fn to_float(&self) -> f64

Convert to a float following SQLite’s type coercion rules.

  • NULL -> 0.0
  • Integer -> as f64
  • Float -> itself
  • Text -> attempt to parse, 0.0 on failure
  • Blob -> 0.0
Source

pub fn to_text(&self) -> String

Convert to text following SQLite’s type coercion rules.

Source

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

Returns the SQLite typeof() string for this value.

Matches C sqlite3: “null”, “integer”, “real”, “text”, or “blob”.

Source

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

Returns the SQLite length() result for this value.

  • NULL → NULL (represented as None)
  • TEXT → character count
  • BLOB → byte count
  • INTEGER/REAL → character count of text representation
Source

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

Check equality for UNIQUE constraint purposes.

In SQLite, NULL != NULL for uniqueness: if either value is NULL, the result is false (they are never considered duplicates). Non-NULL values compare by storage class ordering (same as PartialEq).

Source

pub fn sql_add(&self, other: &Self) -> Self

Add two values following SQLite’s overflow semantics.

  • Integer + Integer: checked add; overflows promote to REAL.
  • Any REAL operand: float addition.
  • NULL propagates (NULL + x = NULL).
  • Non-numeric types coerced to numeric first.
Source

pub fn sql_sub(&self, other: &Self) -> Self

Subtract two values following SQLite’s overflow semantics.

Integer - Integer with overflow promotes to REAL.

Source

pub fn sql_mul(&self, other: &Self) -> Self

Multiply two values following SQLite’s overflow semantics.

Integer * Integer with overflow promotes to REAL.

Trait Implementations§

Source§

impl Clone for SqliteValue

Source§

fn clone(&self) -> SqliteValue

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 SqliteValue

Source§

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

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

impl<'de> Deserialize<'de> for SqliteValue

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 SqliteValue

Source§

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

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

impl From<&[u8]> for SqliteValue

Source§

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

Converts to this type from the input type.
Source§

impl From<&str> for SqliteValue

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Self>> From<Option<T>> for SqliteValue

Source§

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

Converts to this type from the input type.
Source§

impl From<String> for SqliteValue

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for SqliteValue

Source§

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

Converts to this type from the input type.
Source§

impl From<f64> for SqliteValue

Source§

fn from(f: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for SqliteValue

Source§

fn from(i: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for SqliteValue

Source§

fn from(i: i64) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for SqliteValue

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 PartialOrd for SqliteValue

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for SqliteValue

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

Auto Trait Implementations§

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