1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! Schema representation for Toasty, split into three layers.
//!
//! - [`app`] -- Model-level definitions: fields, relations, constraints. This
//! is what the generated Rust code sees.
//! - [`db`] -- Table/column-level definitions. This is what the database sees.
//! - [`mapping`] -- Connects app fields to database columns, supporting
//! non-1:1 mappings such as embedded structs and enums.
//!
//! The top-level [`Schema`] struct ties all three layers together and is
//! constructed via [`Builder`].
//!
//! # Examples
//!
//! ```ignore
//! use toasty_core::schema::{Schema, Builder};
//!
//! let schema = Builder::new()
//! .build(app_schema, &driver_capability)
//! .expect("schema should be valid");
//!
//! // Look up the database table backing a model
//! let table = schema.table_for(model_id);
//! ```
/// Application-level (model-oriented) schema definitions.
pub use Builder;
/// Database-level (table/column-oriented) schema definitions.
/// Mapping between the app layer and the database layer.
use Mapping;
pub use Name;
use crateResult;
use ModelId;
use ;
/// The combined schema: app-level models, database-level tables, and the
/// mapping that connects them.
///
/// Constructed with [`Builder`] and validated on creation. Immutable at runtime.
///
/// # Examples
///
/// ```ignore
/// use toasty_core::Schema;
///
/// fn inspect(schema: &Schema) {
/// for (id, model) in &schema.app.models {
/// let table = schema.table_for(*id);
/// println!("{} -> {}", model.name().snake_case(), table.name);
/// }
/// }
/// ```