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