graphos_adapters/query/gql/
ast.rs1use graphos_common::utils::error::SourceSpan;
4
5#[derive(Debug, Clone)]
7pub enum Statement {
8 Query(QueryStatement),
10 DataModification(DataModificationStatement),
12 Schema(SchemaStatement),
14}
15
16#[derive(Debug, Clone)]
18pub struct QueryStatement {
19 pub match_clause: Option<MatchClause>,
21 pub where_clause: Option<WhereClause>,
23 pub return_clause: ReturnClause,
25 pub span: Option<SourceSpan>,
27}
28
29#[derive(Debug, Clone)]
31pub struct MatchClause {
32 pub patterns: Vec<Pattern>,
34 pub span: Option<SourceSpan>,
36}
37
38#[derive(Debug, Clone)]
40pub enum Pattern {
41 Node(NodePattern),
43 Path(PathPattern),
45}
46
47#[derive(Debug, Clone)]
49pub struct NodePattern {
50 pub variable: Option<String>,
52 pub labels: Vec<String>,
54 pub properties: Vec<(String, Expression)>,
56 pub span: Option<SourceSpan>,
58}
59
60#[derive(Debug, Clone)]
62pub struct PathPattern {
63 pub source: NodePattern,
65 pub edges: Vec<EdgePattern>,
67 pub span: Option<SourceSpan>,
69}
70
71#[derive(Debug, Clone)]
73pub struct EdgePattern {
74 pub variable: Option<String>,
76 pub types: Vec<String>,
78 pub direction: EdgeDirection,
80 pub target: NodePattern,
82 pub span: Option<SourceSpan>,
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88pub enum EdgeDirection {
89 Outgoing,
91 Incoming,
93 Undirected,
95}
96
97#[derive(Debug, Clone)]
99pub struct WhereClause {
100 pub expression: Expression,
102 pub span: Option<SourceSpan>,
104}
105
106#[derive(Debug, Clone)]
108pub struct ReturnClause {
109 pub distinct: bool,
111 pub items: Vec<ReturnItem>,
113 pub order_by: Option<OrderByClause>,
115 pub skip: Option<Expression>,
117 pub limit: Option<Expression>,
119 pub span: Option<SourceSpan>,
121}
122
123#[derive(Debug, Clone)]
125pub struct ReturnItem {
126 pub expression: Expression,
128 pub alias: Option<String>,
130 pub span: Option<SourceSpan>,
132}
133
134#[derive(Debug, Clone)]
136pub struct OrderByClause {
137 pub items: Vec<OrderByItem>,
139 pub span: Option<SourceSpan>,
141}
142
143#[derive(Debug, Clone)]
145pub struct OrderByItem {
146 pub expression: Expression,
148 pub order: SortOrder,
150}
151
152#[derive(Debug, Clone, Copy, PartialEq, Eq)]
154pub enum SortOrder {
155 Asc,
157 Desc,
159}
160
161#[derive(Debug, Clone)]
163pub enum DataModificationStatement {
164 Insert(InsertStatement),
166 Delete(DeleteStatement),
168 Set(SetStatement),
170}
171
172#[derive(Debug, Clone)]
174pub struct InsertStatement {
175 pub patterns: Vec<Pattern>,
177 pub span: Option<SourceSpan>,
179}
180
181#[derive(Debug, Clone)]
183pub struct DeleteStatement {
184 pub variables: Vec<String>,
186 pub detach: bool,
188 pub span: Option<SourceSpan>,
190}
191
192#[derive(Debug, Clone)]
194pub struct SetStatement {
195 pub assignments: Vec<PropertyAssignment>,
197 pub span: Option<SourceSpan>,
199}
200
201#[derive(Debug, Clone)]
203pub struct PropertyAssignment {
204 pub variable: String,
206 pub property: String,
208 pub value: Expression,
210}
211
212#[derive(Debug, Clone)]
214pub enum SchemaStatement {
215 CreateNodeType(CreateNodeTypeStatement),
217 CreateEdgeType(CreateEdgeTypeStatement),
219}
220
221#[derive(Debug, Clone)]
223pub struct CreateNodeTypeStatement {
224 pub name: String,
226 pub properties: Vec<PropertyDefinition>,
228 pub span: Option<SourceSpan>,
230}
231
232#[derive(Debug, Clone)]
234pub struct CreateEdgeTypeStatement {
235 pub name: String,
237 pub properties: Vec<PropertyDefinition>,
239 pub span: Option<SourceSpan>,
241}
242
243#[derive(Debug, Clone)]
245pub struct PropertyDefinition {
246 pub name: String,
248 pub data_type: String,
250 pub nullable: bool,
252}
253
254#[derive(Debug, Clone)]
256pub enum Expression {
257 Literal(Literal),
259 Variable(String),
261 PropertyAccess {
263 variable: String,
265 property: String,
267 },
268 Binary {
270 left: Box<Expression>,
272 op: BinaryOp,
274 right: Box<Expression>,
276 },
277 Unary {
279 op: UnaryOp,
281 operand: Box<Expression>,
283 },
284 FunctionCall {
286 name: String,
288 args: Vec<Expression>,
290 },
291 List(Vec<Expression>),
293 Case {
295 input: Option<Box<Expression>>,
297 whens: Vec<(Expression, Expression)>,
299 else_clause: Option<Box<Expression>>,
301 },
302}
303
304#[derive(Debug, Clone)]
306pub enum Literal {
307 Null,
309 Bool(bool),
311 Integer(i64),
313 Float(f64),
315 String(String),
317}
318
319#[derive(Debug, Clone, Copy, PartialEq, Eq)]
321pub enum BinaryOp {
322 Eq,
325 Ne,
327 Lt,
329 Le,
331 Gt,
333 Ge,
335
336 And,
339 Or,
341
342 Add,
345 Sub,
347 Mul,
349 Div,
351 Mod,
353
354 Concat,
357 Like,
359 In,
361}
362
363#[derive(Debug, Clone, Copy, PartialEq, Eq)]
365pub enum UnaryOp {
366 Not,
368 Neg,
370 IsNull,
372 IsNotNull,
374}