ormdantic_schema/
namespace.rs1use crate::TableDef;
2
3#[derive(Debug, Clone, Default, PartialEq, Eq)]
4pub struct SchemaDef {
5 namespaces: Vec<NamespaceDef>,
6 tables: Vec<TableDef>,
7}
8
9impl SchemaDef {
10 pub fn new() -> Self {
11 Self::default()
12 }
13
14 pub fn from_tables(tables: Vec<TableDef>) -> Self {
15 Self {
16 namespaces: Vec::new(),
17 tables,
18 }
19 }
20
21 pub fn with_namespaces(mut self, namespaces: Vec<NamespaceDef>) -> Self {
22 self.namespaces = namespaces;
23 self
24 }
25
26 pub fn namespaces(&self) -> &[NamespaceDef] {
27 &self.namespaces
28 }
29
30 pub fn tables(&self) -> &[TableDef] {
31 &self.tables
32 }
33
34 pub fn table(&self, name: &str) -> Option<&TableDef> {
35 self.tables.iter().find(|table| table.name() == name)
36 }
37}
38
39#[derive(Debug, Clone, PartialEq, Eq)]
40pub struct NamespaceDef {
41 name: String,
42 comment: Option<String>,
43}
44
45impl NamespaceDef {
46 pub fn new(name: impl Into<String>) -> Self {
47 Self {
48 name: name.into(),
49 comment: None,
50 }
51 }
52
53 pub fn with_comment(mut self, comment: impl Into<String>) -> Self {
54 self.comment = Some(comment.into());
55 self
56 }
57
58 pub fn name(&self) -> &str {
59 &self.name
60 }
61
62 pub fn comment(&self) -> Option<&str> {
63 self.comment.as_deref()
64 }
65}