1#[derive(Debug, Clone, Copy, PartialEq)]
5pub enum ExplainType {
6 PhysicalPlan,
8 LogicalPlan,
10 Profile,
12}
13
14#[derive(Debug, Clone, PartialEq)]
16pub struct ExportDatabase {
17 pub file_path: String,
19 pub options: std::collections::HashMap<String, String>,
21}
22
23#[derive(Debug, Clone, PartialEq)]
25pub struct ImportDatabase {
26 pub file_path: String,
28}
29
30#[derive(Debug, Clone, PartialEq)]
32pub struct AnalyzeStatement {
33 pub table_name: Option<String>,
35}
36
37#[derive(Debug, Clone, Copy, PartialEq)]
39pub enum TransactionAction {
40 Begin,
41 Commit,
42 Rollback,
43 Checkpoint,
44}
45
46#[derive(Debug, Clone, PartialEq)]
48pub struct TransactionStatement {
49 pub action: TransactionAction,
50}
51
52#[derive(Debug, Clone, Copy, PartialEq)]
54pub enum ExtensionAction {
55 Install,
56 Load,
57 Uninstall,
58}
59
60#[derive(Debug, Clone, PartialEq)]
62pub struct ExtensionStatement {
63 pub action: ExtensionAction,
64 pub name: String,
65}
66
67#[derive(Debug, Clone, PartialEq)]
69pub struct AttachDatabase {
70 pub path: String,
71 pub alias: String,
72 pub options: std::collections::HashMap<String, String>,
73}
74
75#[derive(Debug, Clone, PartialEq)]
77pub struct DetachDatabase {
78 pub alias: String,
79}
80
81#[derive(Debug, Clone, PartialEq)]
83pub struct UseDatabase {
84 pub alias: String,
85}
86
87#[derive(Debug, Clone, PartialEq)]
89pub struct LoadFrom {
90 pub path: String,
91 pub options: std::collections::HashMap<String, String>,
92}
93
94#[derive(Debug, Clone, PartialEq)]
96pub struct ExplainStatement {
97 pub statement: Box<Statement>,
99 pub explain_type: ExplainType,
101}
102
103#[derive(Debug, Clone, PartialEq)]
105pub enum Statement {
106 Query(Query),
107 CreateNodeTable(CreateNodeTable),
108 CreateRelTable(CreateRelTable),
109 DropTable(DropTable),
110 CopyFrom(CopyFrom),
111 CopyTo(CopyTo),
112 AlterTable(AlterTable),
113 CreateVectorIndex(CreateVectorIndex),
114 CreateIndex(CreateIndex),
115 DropIndex(DropIndex),
116 Union(UnionStatement),
117 Merge(MergeStatement),
118 StandaloneCall(StandaloneCall),
119 CreateDml(CreateClause),
120 Explain(ExplainStatement),
121 CreateSequence(CreateSequence),
122 DropSequence(DropSequence),
123 CreateMacro(CreateMacro),
124 ExportDatabase(ExportDatabase),
125 ImportDatabase(ImportDatabase),
126 Analyze(AnalyzeStatement),
127 CreateFtsIndex(CreateFtsIndex),
128 Transaction(TransactionStatement),
129 Extension(ExtensionStatement),
130 AttachDatabase(AttachDatabase),
131 DetachDatabase(DetachDatabase),
132 UseDatabase(UseDatabase),
133 LoadFrom(LoadFrom),
134 CreateType(CreateType),
135 CommentOnTable(CommentOnTable),
136 CreateGraph(CreateGraph),
137 UseGraph(UseGraph),
138 DropGraph(DropGraph),
139}
140
141#[derive(Debug, Clone, PartialEq)]
143pub struct Query {
144 pub clauses: Vec<Clause>,
145}
146
147#[derive(Debug, Clone, PartialEq)]
149pub enum Clause {
150 Match(MatchClause),
151 Return(ReturnClause),
152 Where(WhereClause),
153 Create(CreateClause),
154 Delete(DeleteClause),
155 Set(SetClause),
156 OptionalMatch(OptionalMatchClause),
157 With(ReturnClause),
158 Unwind(UnwindClause),
159 Foreach(ForeachClause),
160}
161
162#[derive(Debug, Clone, PartialEq)]
163pub struct ForeachClause {
164 pub variable: String,
165 pub expression: Expression,
166 pub clauses: Vec<Clause>,
168}
169
170#[derive(Debug, Clone, PartialEq)]
171pub struct UnwindClause {
172 pub expression: Expression,
173 pub variable: String,
174}
175
176#[derive(Debug, Clone, PartialEq)]
177pub struct SetClause {
178 pub items: Vec<SetItem>,
179}
180
181#[derive(Debug, Clone, PartialEq)]
182pub struct SetItem {
183 pub property: Expression,
184 pub value: Expression,
185}
186
187#[derive(Debug, Clone, PartialEq)]
188pub struct DeleteClause {
189 pub detach: bool,
190 pub expressions: Vec<Expression>,
191}
192
193#[derive(Debug, Clone, PartialEq)]
194pub struct MatchClause {
195 pub patterns: Vec<Pattern>,
196 pub fts_query: Option<FtsQuery>,
198}
199
200#[derive(Debug, Clone, PartialEq)]
202pub struct FtsQuery {
203 pub index_name: String,
204 pub query_string: String,
205}
206
207#[derive(Debug, Clone, PartialEq)]
209pub struct CreateFtsIndex {
210 pub index_name: String,
211 pub table_name: String,
212 pub column_name: String,
213 pub if_not_exists: bool,
214}
215
216#[derive(Debug, Clone, PartialEq)]
217pub struct OptionalMatchClause {
218 pub patterns: Vec<Pattern>,
219}
220
221#[derive(Debug, Clone, PartialEq)]
222pub struct ReturnClause {
223 pub expressions: Vec<ReturnItem>,
224 pub distinct: bool,
225 pub order_by: Option<Vec<OrderByItem>>,
227 pub limit: Option<u64>,
229 pub skip: Option<u64>,
231}
232
233#[derive(Debug, Clone, PartialEq)]
234pub struct ReturnItem {
235 pub expression: Expression,
236 pub alias: Option<String>,
237}
238
239#[derive(Debug, Clone, PartialEq)]
241pub struct OrderByItem {
242 pub expression: Expression,
244 pub ascending: bool,
246}
247
248#[derive(Debug, Clone, PartialEq)]
249pub struct WhereClause {
250 pub expression: Expression,
251}
252
253#[derive(Debug, Clone, PartialEq)]
254pub struct CreateClause {
255 pub patterns: Vec<Pattern>,
256}
257
258#[derive(Debug, Clone, PartialEq)]
260pub struct Pattern {
261 pub node: Option<NodePattern>,
262 pub edge: Option<EdgePattern>,
263}
264
265#[derive(Debug, Clone, PartialEq)]
266pub struct NodePattern {
267 pub variable: Option<String>,
268 pub labels: Vec<String>,
269 pub properties: Vec<(String, Expression)>,
270}
271
272#[derive(Debug, Clone, PartialEq)]
273pub struct EdgePattern {
274 pub variable: Option<String>,
275 pub labels: Vec<String>,
276 pub direction: EdgeDirection,
277 pub properties: Vec<(String, Expression)>,
278 pub lower_bound: Option<u64>,
279 pub upper_bound: Option<u64>,
280}
281
282#[derive(Debug, Clone, PartialEq)]
283pub enum EdgeDirection {
284 LeftToRight,
285 RightToLeft,
286 Both,
287}
288
289impl ExplainStatement {
290 pub fn new(statement: Statement, explain_type: ExplainType) -> Self {
292 Self {
293 statement: Box::new(statement),
294 explain_type,
295 }
296 }
297}
298
299#[derive(Debug, Clone, PartialEq)]
301pub enum Expression {
302 Constant(Constant),
303 Variable(String),
304 Parameter(String),
306 PropertyAccess(Box<Expression>, String),
307 FunctionCall(String, Vec<Expression>),
308 BinaryOp(BinaryOp, Box<Expression>, Box<Expression>),
309 UnaryOp(UnaryOp, Box<Expression>),
310 List(Vec<Expression>),
311 Map(Vec<(String, Expression)>),
312 ExistsSubquery(Box<Query>),
314 Case(CaseExpr),
316 Star,
319 ListPredicate {
322 quantifier: Quantifier,
323 list: Box<Expression>,
324 var_name: String,
325 predicate: Box<Expression>,
326 },
327 Lambda {
330 var_name: String,
331 body: Box<Expression>,
332 },
333}
334
335#[derive(Debug, Clone, Copy, PartialEq)]
337pub enum Quantifier {
338 Any,
339 All,
340 None,
341 Single,
342}
343
344#[derive(Debug, Clone, PartialEq)]
346pub struct CaseAlternative {
347 pub when: Expression,
349 pub then: Expression,
351}
352
353#[derive(Debug, Clone, PartialEq)]
355pub struct CaseExpr {
356 pub subject: Option<Box<Expression>>,
358 pub alternatives: Vec<CaseAlternative>,
360 pub else_expr: Option<Box<Expression>>,
362}
363
364#[derive(Debug, Clone, PartialEq)]
365pub enum Constant {
366 Null,
367 Bool(bool),
368 Integer(i64),
369 Float(f64),
370 String(String),
371}
372
373#[derive(Debug, Clone, Copy, PartialEq)]
374pub enum BinaryOp {
375 Add,
376 Subtract,
377 Multiply,
378 Divide,
379 Modulo,
380 Equal,
381 NotEqual,
382 LessThan,
383 LessThanOrEqual,
384 GreaterThan,
385 GreaterThanOrEqual,
386 And,
387 Or,
388 Xor,
389 Concat,
390 In,
392 NotIn,
394 StartsWith,
396 EndsWith,
398 Contains,
400 Like,
402}
403
404#[derive(Debug, Clone, Copy, PartialEq)]
405pub enum UnaryOp {
406 Not,
407 Negate,
408 IsNull,
410 IsNotNull,
412}
413
414#[derive(Debug, Clone, PartialEq)]
416pub struct CreateNodeTable {
417 pub name: String,
418 pub columns: Vec<ColumnDef>,
419 pub primary_key: String,
420}
421
422#[derive(Debug, Clone, PartialEq)]
423pub struct CreateRelTable {
424 pub name: String,
425 pub from: String,
426 pub to: String,
427 pub columns: Vec<ColumnDef>,
428}
429
430#[derive(Debug, Clone, PartialEq)]
431pub struct DropTable {
432 pub name: String,
433}
434
435#[derive(Debug, Clone, PartialEq)]
437pub struct CreateIndex {
438 pub index_type: String,
439 pub index_name: String,
440 pub table_name: String,
441 pub variable: String,
442 pub property: String,
443 pub conflict_action: Option<String>,
444}
445
446#[derive(Debug, Clone, PartialEq)]
448pub struct DropIndex {
449 pub index_name: String,
450 pub table_name: String,
451}
452
453#[derive(Debug, Clone, PartialEq)]
455pub struct AlterTable {
456 pub table_name: String,
457 pub action: AlterAction,
458}
459
460#[derive(Debug, Clone, PartialEq)]
461pub enum AlterAction {
462 AddColumn { name: String, type_name: String },
463 DropColumn { name: String },
464 RenameColumn { old_name: String, new_name: String },
465 RenameTable { new_name: String },
466}
467
468#[derive(Debug, Clone, PartialEq)]
470pub struct UnionStatement {
471 pub left: Query,
472 pub right: Query,
473 pub all: bool,
474}
475
476#[derive(Debug, Clone, PartialEq)]
478pub struct CopyFrom {
479 pub table_name: String,
480 pub file_path: String,
481 pub options: std::collections::HashMap<String, String>,
482}
483
484#[derive(Debug, Clone, PartialEq)]
488pub struct CopyTo {
489 pub query: Query,
490 pub file_path: String,
491 pub format: CopyToFormat,
492 pub header: bool,
493}
494
495#[derive(Debug, Clone, PartialEq)]
496pub enum CopyToFormat {
497 Csv,
498 Parquet,
499}
500
501#[derive(Debug, Clone, PartialEq)]
503pub struct MergeStatement {
504 pub patterns: Vec<Pattern>,
505 pub on_create: Vec<SetItem>,
506 pub on_match: Vec<SetItem>,
507}
508
509#[derive(Debug, Clone, PartialEq)]
511pub struct StandaloneCall {
512 pub function_name: String,
513 pub args: Vec<Expression>,
514}
515
516#[derive(Debug, Clone, PartialEq)]
528pub struct CreateSequence {
529 pub name: String,
530 pub if_not_exists: bool,
531 pub or_replace: bool,
532 pub start_with: Option<i64>,
534 pub increment: Option<i64>,
536 pub min_value: Option<i64>,
538 pub max_value: Option<i64>,
540 pub cycle: Option<bool>,
542}
543
544#[derive(Debug, Clone, PartialEq)]
546pub struct DropSequence {
547 pub name: String,
548 pub if_exists: bool,
549}
550
551#[derive(Debug, Clone, PartialEq)]
560pub struct CreateMacro {
561 pub name: String,
563 pub positional_args: Vec<String>,
565 pub default_args: Vec<(String, Expression)>,
567 pub expression: Box<Expression>,
569}
570
571#[derive(Debug, Clone, PartialEq)]
573pub struct CreateVectorIndex {
574 pub index_name: String,
575 pub table_name: String,
576 pub column_name: String,
577 pub metric: String,
578 pub dimensions: u64,
579}
580
581#[derive(Debug, Clone, PartialEq)]
582pub struct ColumnDef {
583 pub name: String,
584 pub type_name: String,
585 pub compression: Option<String>,
586}
587
588#[derive(Debug, Clone, PartialEq)]
590pub struct CreateType {
591 pub name: String,
592 pub type_name: String,
593}
594
595#[derive(Debug, Clone, PartialEq)]
597pub struct CommentOnTable {
598 pub table_name: String,
599 pub comment: String,
600}
601
602#[derive(Debug, Clone, PartialEq)]
604pub struct CreateGraph {
605 pub name: String,
606 pub is_any: bool,
607}
608
609#[derive(Debug, Clone, PartialEq)]
611pub struct UseGraph {
612 pub name: String,
613}
614
615#[derive(Debug, Clone, PartialEq)]
617pub struct DropGraph {
618 pub name: String,
619}