relate_executor/graph/
schema_api.rs1use relate_catalog::{ConstraintDef, IndexDef};
5
6use super::*;
7
8impl Graph {
9 pub fn named_indexes(&self) -> Vec<IndexDef> {
10 self.catalog
11 .lock()
12 .unwrap()
13 .indexes
14 .values()
15 .cloned()
16 .collect()
17 }
18
19 pub fn schema_snapshot(&self) -> SchemaSnapshot {
24 self.schema_snapshot_with_hook(|| {})
25 }
26
27 pub(super) fn schema_snapshot_with_hook(&self, after_catalog: impl FnOnce()) -> SchemaSnapshot {
28 let (indexes, constraints) = {
29 let catalog = self.catalog.lock().unwrap();
30 (
31 catalog.indexes.values().cloned().collect(),
32 catalog.constraints.values().cloned().collect(),
33 )
34 };
35 after_catalog();
36 let show = self.capture_show_schema();
41 SchemaSnapshot {
42 indexes,
43 constraints,
44 show,
45 }
46 }
47
48 pub(crate) fn capture_show_schema(&self) -> ShowSchema {
51 ShowSchema::capture(self.databases().snapshot(), &self.theater.lock().unwrap())
52 }
53
54 pub fn named_constraints(&self) -> Vec<ConstraintDef> {
55 self.catalog
56 .lock()
57 .unwrap()
58 .constraints
59 .values()
60 .cloned()
61 .collect()
62 }
63
64 pub fn install_named_constraint(&self, def: ConstraintDef) -> Result<()> {
71 self.catalog.lock().unwrap().insert_constraint(def)
72 }
73
74 pub fn named_index(&self, name: &str) -> Option<IndexDef> {
75 self.catalog.lock().unwrap().indexes.get(name).cloned()
76 }
77
78 pub fn has_constraint(&self, name: &str) -> bool {
80 self.catalog.lock().unwrap().constraints.contains_key(name)
81 }
82
83 pub fn named_index_by_schema(&self, label: &str, property: &str) -> Option<IndexDef> {
84 self.catalog
85 .lock()
86 .unwrap()
87 .index_by_schema(label, property)
88 .cloned()
89 }
90
91 pub fn install_named_index(&self, def: IndexDef) -> Result<()> {
92 self.catalog.lock().unwrap().insert_index(def)
93 }
94}