1pub mod schema;
5
6pub mod mutate;
8
9pub mod query;
11
12use std::collections::HashMap;
13
14use serde::{Deserialize, Serialize};
15use serde_json::Value as JsonValue;
16
17use crate::schema::{format_edge_table_name, format_node_attribute_name, format_node_table_name};
18
19use super::entities::entity_attribute::Datatype;
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct EntityJson {
24 pub name: String,
26 pub attributes: Vec<EntityAttrJson>,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct EntityAttrJson {
33 pub name: String,
35 pub datatype: Datatype,
37}
38
39impl EntityJson {
40 pub fn get_table_name(&self) -> String {
42 format_node_table_name(&self.name)
43 }
44}
45
46impl EntityAttrJson {
47 pub fn get_column_name(&self) -> String {
49 format_node_attribute_name(&self.name)
50 }
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct RelationJson {
56 pub name: String,
58 pub from_entity: String,
60 pub to_entity: String,
62 pub directed: bool,
64}
65
66impl RelationJson {
67 pub fn get_table_name(&self) -> String {
69 format_edge_table_name(&self.name)
70 }
71}
72
73#[derive(Debug, Clone, Deserialize, Serialize)]
75pub struct EdgeJson {
76 pub name: String,
78 pub from_node: String,
80 pub to_node: String,
82}
83
84#[derive(Debug, Clone, Deserialize, Serialize)]
86pub struct ClearEdgeJson {
87 pub name: String,
89 pub node: String,
91}
92
93#[derive(Debug, Clone, Deserialize, Serialize)]
95pub struct NodeJson {
96 pub of: String,
98 pub name: String,
100 pub attributes: HashMap<String, JsonValue>,
102}
103
104#[derive(Debug, Clone, Deserialize, Serialize)]
106pub struct Node {
107 pub name: String,
109 pub attributes: HashMap<String, JsonValue>,
111}
112
113impl Node {
114 pub fn new<S>(name: S) -> Self
116 where
117 S: Into<String>,
118 {
119 Self {
120 name: name.into(),
121 attributes: Default::default(),
122 }
123 }
124
125 pub fn new_vec<S>(names: Vec<S>) -> Vec<Self>
127 where
128 S: Into<String>,
129 {
130 names.into_iter().map(Self::new).collect()
131 }
132}
133
134#[derive(Debug, Clone, Deserialize, Serialize)]
136pub struct NodeJsonBatch {
137 pub of: String,
139 pub nodes: Vec<Node>,
141}
142
143#[derive(Debug, Clone, Deserialize, Serialize)]
145pub struct Edge {
146 pub from_node: String,
148 pub to_node: String,
150}
151
152impl Edge {
153 pub fn new<SFrom, STo>(from: SFrom, to: STo) -> Self
155 where
156 SFrom: Into<String>,
157 STo: Into<String>,
158 {
159 Self {
160 from_node: from.into(),
161 to_node: to.into(),
162 }
163 }
164
165 pub fn new_vec<SFrom, STo>(pairs: Vec<(SFrom, STo)>) -> Vec<Self>
167 where
168 SFrom: Into<String>,
169 STo: Into<String>,
170 {
171 pairs
172 .into_iter()
173 .map(|(from, to)| Self::new(from, to))
174 .collect()
175 }
176}
177
178#[derive(Debug, Clone, Deserialize, Serialize)]
180pub struct EdgeJsonBatch {
181 pub of: String,
183 pub edges: Vec<Edge>,
185}
186
187#[derive(Debug, Clone, Serialize, Deserialize)]
189#[serde(rename_all = "camelCase")]
190pub enum ConnectivityTypeJson {
191 Simple,
193 Compound,
195 Complex03,
197 Complex05,
199 Complex07,
201 Out,
203}
204
205impl Default for ConnectivityTypeJson {
206 fn default() -> Self {
207 Self::Simple
208 }
209}
210
211impl ConnectivityTypeJson {
212 pub fn to_column_name<S: Into<String>>(self, relation_name: S) -> String {
214 format!(
215 "{}_{}",
216 relation_name.into(),
217 match self {
218 Self::Simple => "in_conn",
219 Self::Compound => "in_conn_compound",
220 Self::Complex03 => "in_conn_complex03",
221 Self::Complex05 => "in_conn_complex05",
222 Self::Complex07 => "in_conn_complex07",
223 Self::Out => "out_conn",
224 }
225 )
226 }
227}