good_ormning/sqlite/schema/
table.rs1use std::{
2 fmt::{
3 Debug,
4 Display,
5 },
6 rc::Rc,
7 ops::Deref,
8 hash::Hash,
9};
10
11#[derive(Clone, Eq, PartialEq, Hash, Debug, PartialOrd, Ord)]
12pub struct SchemaTableId(pub String);
13
14impl Display for SchemaTableId {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 Display::fmt(&self.0, f)
17 }
18}
19
20#[derive(Debug)]
21pub struct Table_ {
22 pub schema_id: SchemaTableId,
23 pub id: String,
24}
25
26#[derive(Clone, Debug)]
27pub struct Table(pub Rc<Table_>);
28
29impl Hash for Table {
30 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
31 self.0.schema_id.hash(state)
32 }
33}
34
35impl PartialEq for Table {
36 fn eq(&self, other: &Self) -> bool {
37 self.schema_id == other.schema_id
38 }
39}
40
41impl Eq for Table { }
42
43impl Deref for Table {
44 type Target = Table_;
45
46 fn deref(&self) -> &Self::Target {
47 self.0.as_ref()
48 }
49}
50
51impl Display for Table {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 Display::fmt(&format!("{} ({})", self.id, self.schema_id.0), f)
54 }
55}