pub trait Table {
type Row;
const NAME: &'static str;
const COLUMNS: &'static [&'static str];
const PRIMARY_KEY: Option<&'static str>;
}
pub trait Column {
type Table: Table;
type Type;
const NAME: &'static str;
const NULLABLE: bool;
const PRIMARY_KEY: bool;
}
pub trait TypedColumn<T>: Column<Type = T> {}
pub trait Selectable<T: Table> {
fn column_names() -> &'static [&'static str];
}
impl<T: Table, C: Column<Table = T>> Selectable<T> for C {
fn column_names() -> &'static [&'static str] {
&[C::NAME]
}
}
#[derive(Debug, Clone)]
pub struct ColumnSchema {
pub name: &'static str,
pub rust_type: &'static str,
pub nullable: bool,
pub primary_key: bool,
pub unique: bool,
pub autoincrement: bool,
pub default_expr: Option<&'static str>,
}
pub trait TableSchema: Table {
const SCHEMA: &'static [ColumnSchema];
}
pub trait RustTypeMapping {
fn map_type(&self, rust_type: &str) -> crate::ast::DataType;
}
macro_rules! impl_selectable_tuple {
($($idx:tt: $col:ident),+) => {
impl<T: Table, $($col: Column<Table = T>),+> Selectable<T> for ($($col,)+) {
fn column_names() -> &'static [&'static str] {
&[$($col::NAME),+]
}
}
};
}
impl_selectable_tuple!(0: C0);
impl_selectable_tuple!(0: C0, 1: C1);
impl_selectable_tuple!(0: C0, 1: C1, 2: C2);
impl_selectable_tuple!(0: C0, 1: C1, 2: C2, 3: C3);
impl_selectable_tuple!(0: C0, 1: C1, 2: C2, 3: C3, 4: C4);
impl_selectable_tuple!(0: C0, 1: C1, 2: C2, 3: C3, 4: C4, 5: C5);
impl_selectable_tuple!(0: C0, 1: C1, 2: C2, 3: C3, 4: C4, 5: C5, 6: C6);
impl_selectable_tuple!(0: C0, 1: C1, 2: C2, 3: C3, 4: C4, 5: C5, 6: C6, 7: C7);
impl_selectable_tuple!(0: C0, 1: C1, 2: C2, 3: C3, 4: C4, 5: C5, 6: C6, 7: C7, 8: C8);
impl_selectable_tuple!(0: C0, 1: C1, 2: C2, 3: C3, 4: C4, 5: C5, 6: C6, 7: C7, 8: C8, 9: C9);
impl_selectable_tuple!(0: C0, 1: C1, 2: C2, 3: C3, 4: C4, 5: C5, 6: C6, 7: C7, 8: C8, 9: C9, 10: C10);
impl_selectable_tuple!(0: C0, 1: C1, 2: C2, 3: C3, 4: C4, 5: C5, 6: C6, 7: C7, 8: C8, 9: C9, 10: C10, 11: C11);