#[macro_export]
macro_rules! models {
(
$enum_name:ident($datasource:ty) => {
$($mod_name:ident => $struct_name:ident),* $(,)?
}
) => {
$(
pub mod $mod_name;
pub use $mod_name::*;
)*
pub enum $enum_name {
$(
$struct_name($crate::Table<$datasource, $struct_name>),
)*
}
pub fn model_names() -> Vec<&'static str> {
vec![
$(
stringify!($mod_name),
)*
]
}
pub fn get_table(model: &str, db: $datasource) -> ::vantage_core::Result<$enum_name> {
match model {
$(
stringify!($mod_name) => Ok($enum_name::$struct_name($struct_name::table(db.clone()))),
)*
_ => Err(::vantage_core::VantageError::other(format!("Unknown model: {}", model))),
}
}
pub fn all_tables(db: $datasource) -> ::indexmap::IndexMap<String, $crate::any::AnyTable> {
let mut tables = ::indexmap::IndexMap::new();
$(
tables.insert(
stringify!($mod_name).to_string(),
$crate::any::AnyTable::new($struct_name::table(db.clone())),
);
)*
tables
}
};
}