toasty_core/
schema.rs

1pub mod app;
2
3mod builder;
4pub use builder::Builder;
5
6pub mod db;
7
8pub mod mapping;
9use mapping::Mapping;
10
11mod name;
12pub use name::Name;
13
14mod verify;
15
16use crate::Result;
17use app::ModelId;
18use db::{Table, TableId};
19
20#[derive(Debug)]
21pub struct Schema {
22    /// Application-level schema
23    pub app: app::Schema,
24
25    /// Database-level schema
26    pub db: db::Schema,
27
28    /// Maps the app-level schema to the db-level schema
29    pub mapping: Mapping,
30}
31
32impl Schema {
33    pub fn builder() -> Builder {
34        Builder::default()
35    }
36
37    pub fn mapping_for(&self, id: impl Into<ModelId>) -> &mapping::Model {
38        self.mapping.model(id)
39    }
40
41    pub fn table_for(&self, id: impl Into<ModelId>) -> &Table {
42        self.db.table(self.table_id_for(id))
43    }
44
45    pub fn table_id_for(&self, id: impl Into<ModelId>) -> TableId {
46        self.mapping.model(id).table
47    }
48}