1use std::collections::BTreeMap;
16
17use super::PgqDataType;
18
19pub trait PgqCatalog {
20 fn property_graph(&self, name: &[String]) -> Option<&PropertyGraphSchema>;
21}
22
23#[derive(Debug, Default, Clone, PartialEq, Eq)]
24pub struct PropertyGraphCatalog {
25 graphs: BTreeMap<Vec<String>, PropertyGraphSchema>,
26}
27
28impl PropertyGraphCatalog {
29 pub fn insert(&mut self, graph: PropertyGraphSchema) -> Option<PropertyGraphSchema> {
30 self.graphs.insert(graph.name.clone(), graph)
31 }
32}
33
34impl PgqCatalog for PropertyGraphCatalog {
35 fn property_graph(&self, name: &[String]) -> Option<&PropertyGraphSchema> {
36 self.graphs.get(name)
37 }
38}
39
40#[derive(Debug, Clone, PartialEq, Eq)]
41pub struct PropertyGraphSchema {
42 pub name: Vec<String>,
43 pub vertex_labels: BTreeMap<String, PropertyGraphElementSchema>,
44 pub edge_labels: BTreeMap<String, PropertyGraphElementSchema>,
45}
46
47impl PropertyGraphSchema {
48 pub fn new(name: impl IntoIterator<Item = impl Into<String>>) -> Self {
49 Self {
50 name: name.into_iter().map(Into::into).collect(),
51 vertex_labels: BTreeMap::new(),
52 edge_labels: BTreeMap::new(),
53 }
54 }
55
56 pub fn add_vertex_label(
57 &mut self,
58 name: impl Into<String>,
59 schema: PropertyGraphElementSchema,
60 ) {
61 self.vertex_labels.insert(name.into(), schema);
62 }
63
64 pub fn add_edge_label(&mut self, name: impl Into<String>, schema: PropertyGraphElementSchema) {
65 self.edge_labels.insert(name.into(), schema);
66 }
67}
68
69#[derive(Debug, Default, Clone, PartialEq, Eq)]
70pub struct PropertyGraphElementSchema {
71 pub properties: BTreeMap<String, PgqDataType>,
72}
73
74impl PropertyGraphElementSchema {
75 pub fn with_property(mut self, name: impl Into<String>, data_type: PgqDataType) -> Self {
76 self.properties.insert(name.into(), data_type);
77 self
78 }
79}
80
81#[derive(Debug, Default, Clone, PartialEq, Eq)]
82pub struct PgqBindingContext {
83 pub outer_columns: BTreeMap<Vec<String>, PgqDataType>,
84}
85
86impl PgqBindingContext {
87 pub fn with_outer_column(
88 mut self,
89 name: impl IntoIterator<Item = impl Into<String>>,
90 data_type: PgqDataType,
91 ) -> Self {
92 self.outer_columns
93 .insert(name.into_iter().map(Into::into).collect(), data_type);
94 self
95 }
96}