From 709eb44ccb8d08ad7f26cdac2932eadc7ccd48e7 Mon Sep 17 00:00:00 2001 From: Melody Horn / boringcactus Date: Fri, 18 Jun 2021 10:12:16 -0600 Subject: make model metadata available in AppConfig --- src/apps.rs | 2 ++ src/bin/tosin-admin.rs | 7 ++++++- src/contrib/admin/mod.rs | 2 ++ src/contrib/admin/models.rs | 6 ++++++ src/db/models/meta.rs | 3 +++ src/db/models/mod.rs | 5 ++++- 6 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/contrib/admin/models.rs create mode 100644 src/db/models/meta.rs (limited to 'src') diff --git a/src/apps.rs b/src/apps.rs index f72a883..8c16136 100644 --- a/src/apps.rs +++ b/src/apps.rs @@ -1,6 +1,8 @@ use crate::db::migration::Migration; +use crate::db::models::ModelMeta; pub struct AppConfig { pub name: &'static str, + pub models: &'static [ModelMeta], pub migrations: &'static [Migration], } diff --git a/src/bin/tosin-admin.rs b/src/bin/tosin-admin.rs index 0a359d3..a0ea850 100644 --- a/src/bin/tosin-admin.rs +++ b/src/bin/tosin-admin.rs @@ -38,8 +38,10 @@ pub mod views; pub use urls::urls; +#[allow(dead_code)] pub const APP: AppConfig = AppConfig { name: module_path!(), + models: models::ALL, migrations: migrations::migrations, }; "#; @@ -49,9 +51,12 @@ use tosin::db::migration::{Migration, gather}; gather!(); "#; const APP_MODELS: &str = r#" -use tosin::db::models::{Model, Id}; +#[allow(unused_imports)] +use tosin::db::models::{Model, Id, gather}; // TODO define models + +gather!(); "#; const APP_URLS: &str = r#" use tosin::urls::{UrlMap, url_map}; diff --git a/src/contrib/admin/mod.rs b/src/contrib/admin/mod.rs index f92e709..8572f8d 100644 --- a/src/contrib/admin/mod.rs +++ b/src/contrib/admin/mod.rs @@ -1,9 +1,11 @@ use crate::apps::AppConfig; mod migrations; +mod models; pub mod site; pub const APP: AppConfig = AppConfig { name: module_path!(), + models: models::ALL, migrations: migrations::migrations, }; diff --git a/src/contrib/admin/models.rs b/src/contrib/admin/models.rs new file mode 100644 index 0000000..7fde44a --- /dev/null +++ b/src/contrib/admin/models.rs @@ -0,0 +1,6 @@ +#[allow(unused_imports)] +use crate::db::models::{Model, Id, ModelMeta}; + +pub const ALL: &[ModelMeta] = &[ + +]; diff --git a/src/db/models/meta.rs b/src/db/models/meta.rs new file mode 100644 index 0000000..50729a8 --- /dev/null +++ b/src/db/models/meta.rs @@ -0,0 +1,3 @@ +pub struct ModelMeta { + pub name: &'static str, +} diff --git a/src/db/models/mod.rs b/src/db/models/mod.rs index 492df92..feadb43 100644 --- a/src/db/models/mod.rs +++ b/src/db/models/mod.rs @@ -1,4 +1,7 @@ -pub use tosin_macros::Model; +pub use tosin_macros::{Model, gather_models as gather}; + +mod meta; +pub use meta::*; pub type Id = usize; -- cgit v1.2.3