diff --git a/src/columnvalueops.rs b/src/columnvalueops.rs index a97010e..17f3cdc 100644 --- a/src/columnvalueops.rs +++ b/src/columnvalueops.rs @@ -5,6 +5,14 @@ pub trait ColumnValueOps: Sized { fn from_string_literal(s: Cow) -> Result>; fn from_number_literal(s: Cow) -> Result>; + fn from_f64(value: f64) -> Self; + fn to_f64(self) -> Result; + + fn from_u64(value: u64) -> Self; + fn to_u64(self) -> Result; + + fn null() -> Self { ColumnValueOps::from_3vl(0) } + fn from_bytes(dbtype: DbType, bytes: Cow<[u8]>) -> Result; fn to_bytes(self, dbtype: DbType) -> Result, ()>; fn get_dbtype(&self) -> DbType; @@ -25,6 +33,8 @@ pub trait ColumnValueOps: Sized { fn equals(&self, rhs: &Self) -> Self; fn not_equals(&self, rhs: &Self) -> Self; + fn is_null(&self) -> bool { self.to_3vl() == 0 } + fn not(&self) -> Self { ColumnValueOps::from_3vl(-self.to_3vl()) } diff --git a/src/types/variant.rs b/src/types/variant.rs index 12f47e5..4491c58 100644 --- a/src/types/variant.rs +++ b/src/types/variant.rs @@ -55,6 +55,32 @@ impl ColumnValueOps for Variant { } } + fn from_f64(value: f64) -> Variant { + Variant::Float(F64NoNaN::new(value).unwrap()) + } + + fn to_f64(self) -> Result { + let num = self.cast(DbType::F64); + if let Some(Variant::Float(float)) = num { + Ok(*float) + } else { + Err(()) + } + } + + fn from_u64(value: u64) -> Variant { + Variant::UnsignedInteger(value) + } + + fn to_u64(self) -> Result { + let num = self.cast(DbType::Integer { signed: false, bytes: 8 }); + if let Some(Variant::UnsignedInteger(i)) = num { + Ok(i) + } else { + Err(()) + } + } + fn from_bytes(dbtype: DbType, bytes: Cow<[u8]>) -> Result { match dbtype { DbType::Null => Ok(Variant::Null),