use std::marker::PhantomData;
use sea_query::DynIden;
#[derive(Debug, Clone, Copy)]
#[allow(clippy::type_complexity)]
pub struct Column<M, T> {
name: &'static str,
_marker: PhantomData<(fn() -> M, fn() -> T)>,
}
impl<M, T> Column<M, T> {
pub const fn new(name: &'static str) -> Self {
Self {
name,
_marker: PhantomData,
}
}
pub fn name(&self) -> &'static str {
self.name
}
pub fn iden(&self) -> sea_query::Alias {
sea_query::Alias::new(self.name)
}
}
#[derive(Debug, Clone)]
pub struct ColumnRef {
pub table: Option<&'static str>,
pub name: &'static str,
}
impl ColumnRef {
pub fn new(name: &'static str) -> Self {
Self { table: None, name }
}
pub fn qualified(table: &'static str, name: &'static str) -> Self {
Self {
table: Some(table),
name,
}
}
pub fn iden(&self) -> DynIden {
sea_query::SeaRc::new(sea_query::Alias::new(self.name))
}
}
impl<M, T> From<Column<M, T>> for ColumnRef {
fn from(c: Column<M, T>) -> Self {
ColumnRef::new(c.name)
}
}