use std::sync::Arc;
use crate::prelude::*;
pub trait TypedColumnValue<T: ColumnType>: UntypedColumnValue {}
impl<T: ColumnType, U: Entity> TypedColumnValue<T> for VirtualColumn<T, U> {}
impl<T: ColumnType, U: Entity> TypedColumnValue<T> for VirtualColumn<Option<T>, U> {}
impl<T: ColumnType, U: Entity> TypedColumnValue<T> for EntityColumn<T, U> {}
impl<T: ColumnType, U: Entity> TypedColumnValue<T> for EntityColumn<Option<T>, U> {}
impl<R: UntypedColumnValue + ColumnType> TypedColumnValue<R> for R {}
pub trait UntypedColumnValue {
fn get_sql(&self) -> BoxedSql;
}
macro_rules! simple_column_value {
($column_type:ty) => {
impl UntypedColumnValue for $column_type {
fn get_sql(&self) -> BoxedSql {
BoxedSql::new("_$i".to_string(), vec![Arc::new(Box::new(self.clone()))])
}
}
};
}
simple_column_value!(bool);
simple_column_value!(i8);
simple_column_value!(i16);
simple_column_value!(i32);
simple_column_value!(i64);
simple_column_value!(u32);
simple_column_value!(f32);
simple_column_value!(f64);
#[cfg(feature = "with-rust-decimal")]
simple_column_value!(rust_decimal::Decimal);
#[cfg(feature = "with-uuid")]
simple_column_value!(uuid::Uuid);
#[cfg(feature = "with-chrono")]
simple_column_value!(chrono::NaiveDateTime);
#[cfg(feature = "with-chrono")]
simple_column_value!(chrono::DateTime<chrono::Utc>);
#[cfg(feature = "with-chrono")]
simple_column_value!(chrono::DateTime<chrono::Local>);
#[cfg(feature = "with-chrono")]
simple_column_value!(chrono::DateTime<chrono::FixedOffset>);
#[cfg(feature = "with-chrono")]
simple_column_value!(chrono::NaiveDate);
#[cfg(feature = "with-chrono")]
simple_column_value!(chrono::NaiveTime);
simple_column_value!(String);
#[cfg(feature = "with-eui48")]
simple_column_value!(eui48::MacAddress);
#[cfg(feature = "with-bit-vec")]
simple_column_value!(bit_vec::BitVec);
#[cfg(feature = "with-time")]
simple_column_value!(time::PrimitiveDateTime);
#[cfg(feature = "with-time")]
simple_column_value!(time::OffsetDateTime);
#[cfg(feature = "with-time")]
simple_column_value!(time::Date);
#[cfg(feature = "with-time")]
simple_column_value!(time::Time);
#[cfg(feature = "with-geo-types")]
simple_column_value!(geo_types::Point);
#[cfg(feature = "with-geo-types")]
simple_column_value!(geo_types::Rect);
#[cfg(feature = "with-geo-types")]
simple_column_value!(geo_types::LineString);
impl<T: ColumnType, U: Entity> UntypedColumnValue for VirtualColumn<T, U> {
fn get_sql(&self) -> BoxedSql {
self.get_sql()
}
}
impl<T: ColumnType, U: Entity> UntypedColumnValue for EntityColumn<T, U> {
fn get_sql(&self) -> BoxedSql {
self.get_sql()
}
}
impl<T: UntypedColumnValue> UntypedColumnValue for Option<T> {
fn get_sql(&self) -> BoxedSql {
if self.is_some() {
self.as_ref().unwrap().get_sql()
} else {
BoxedSql::new(String::from("NULL"), vec![])
}
}
}