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 pub options: std::collections::HashMap<String, String>,
30}
31
32#[derive(Debug, Clone, PartialEq)]
34pub struct AnalyzeStatement {
35 pub table_name: Option<String>,
37}
38
39#[derive(Debug, Clone, Copy, PartialEq)]
41pub enum TransactionAction {
42 Begin,
43 Commit,
44 Rollback,
45 Checkpoint,
46}
47
48#[derive(Debug, Clone, PartialEq)]
50pub struct TransactionStatement {
51 pub action: TransactionAction,
52}
53
54#[derive(Debug, Clone, Copy, PartialEq)]
56pub enum ExtensionAction {
57 Install,
58 Load,
59 Uninstall,
60}
61
62#[derive(Debug, Clone, PartialEq)]
64pub struct ExtensionStatement {
65 pub action: ExtensionAction,
66 pub name: String,
67}
68
69#[derive(Debug, Clone, PartialEq)]
71pub struct AttachDatabase {
72 pub path: String,
73 pub alias: String,
74 pub options: std::collections::HashMap<String, String>,
75}
76
77#[derive(Debug, Clone, PartialEq)]
79pub struct DetachDatabase {
80 pub alias: String,
81}
82
83#[derive(Debug, Clone, PartialEq)]
85pub struct UseDatabase {
86 pub alias: String,
87}
88
89#[derive(Debug, Clone, PartialEq)]
91pub struct LoadFrom {
92 pub path: String,
93 pub options: std::collections::HashMap<String, String>,
94}
95
96#[derive(Debug, Clone, PartialEq)]
98pub struct ExplainStatement {
99 pub statement: Box<Statement>,
101 pub explain_type: ExplainType,
103}
104
105#[derive(Debug, Clone, PartialEq)]
107pub enum Statement {
108 Query(Query),
109 CreateNodeTable(CreateNodeTable),
110 CreateRelTable(CreateRelTable),
111 DropTable(DropTable),
112 CopyFrom(CopyFrom),
113 CopyTo(CopyTo),
114 AlterTable(AlterTable),
115 CreateVectorIndex(CreateVectorIndex),
116 CreateIndex(CreateIndex),
117 DropIndex(DropIndex),
118 Union(UnionStatement),
119 Merge(MergeStatement),
120 StandaloneCall(StandaloneCall),
121 CreateDml(CreateClause),
122 Explain(ExplainStatement),
123 CreateSequence(CreateSequence),
124 DropSequence(DropSequence),
125 CreateMacro(CreateMacro),
126 ExportDatabase(ExportDatabase),
127 ImportDatabase(ImportDatabase),
128 Analyze(AnalyzeStatement),
129 CreateFtsIndex(CreateFtsIndex),
130 Transaction(TransactionStatement),
131 Extension(ExtensionStatement),
132 AttachDatabase(AttachDatabase),
133 DetachDatabase(DetachDatabase),
134 UseDatabase(UseDatabase),
135 LoadFrom(LoadFrom),
136 CreateType(CreateType),
137 CommentOnTable(CommentOnTable),
138 CreateGraph(CreateGraph),
139 UseGraph(UseGraph),
140 DropGraph(DropGraph),
141}
142
143#[derive(Debug, Clone, PartialEq)]
145pub struct Query {
146 pub clauses: Vec<Clause>,
147}
148
149#[derive(Debug, Clone, PartialEq)]
151pub enum Clause {
152 Match(MatchClause),
153 Return(ReturnClause),
154 Where(WhereClause),
155 Create(CreateClause),
156 Delete(DeleteClause),
157 Set(SetClause),
158 OptionalMatch(OptionalMatchClause),
159 With(ReturnClause),
160 Unwind(UnwindClause),
161 Foreach(ForeachClause),
162 Merge(MergeStatement),
163}
164
165#[derive(Debug, Clone, PartialEq)]
166pub struct ForeachClause {
167 pub variable: String,
168 pub expression: Expression,
169 pub clauses: Vec<Clause>,
171}
172
173#[derive(Debug, Clone, PartialEq)]
174pub struct UnwindClause {
175 pub expression: Expression,
176 pub variable: String,
177}
178
179#[derive(Debug, Clone, PartialEq)]
180pub struct SetClause {
181 pub items: Vec<SetItem>,
182}
183
184#[derive(Debug, Clone, PartialEq)]
185pub struct SetItem {
186 pub property: Expression,
187 pub value: Expression,
188}
189
190#[derive(Debug, Clone, PartialEq)]
191pub struct DeleteClause {
192 pub detach: bool,
193 pub expressions: Vec<Expression>,
194}
195
196#[derive(Debug, Clone, PartialEq)]
197pub struct MatchClause {
198 pub patterns: Vec<Pattern>,
199 pub fts_query: Option<FtsQuery>,
201}
202
203#[derive(Debug, Clone, PartialEq)]
205pub struct FtsQuery {
206 pub index_name: String,
207 pub query_string: String,
208}
209
210#[derive(Debug, Clone, PartialEq)]
212pub struct CreateFtsIndex {
213 pub index_name: String,
214 pub table_name: String,
215 pub column_name: String,
216 pub if_not_exists: bool,
217}
218
219#[derive(Debug, Clone, PartialEq)]
220pub struct OptionalMatchClause {
221 pub patterns: Vec<Pattern>,
222}
223
224#[derive(Debug, Clone, PartialEq)]
225pub struct ReturnClause {
226 pub expressions: Vec<ReturnItem>,
227 pub distinct: bool,
228 pub order_by: Option<Vec<OrderByItem>>,
230 pub limit: Option<u64>,
232 pub skip: Option<u64>,
234}
235
236#[derive(Debug, Clone, PartialEq)]
237pub struct ReturnItem {
238 pub expression: Expression,
239 pub alias: Option<String>,
240}
241
242#[derive(Debug, Clone, PartialEq)]
244pub struct OrderByItem {
245 pub expression: Expression,
247 pub ascending: bool,
249}
250
251#[derive(Debug, Clone, PartialEq)]
252pub struct WhereClause {
253 pub expression: Expression,
254}
255
256#[derive(Debug, Clone, PartialEq)]
257pub struct CreateClause {
258 pub patterns: Vec<Pattern>,
259}
260
261#[derive(Debug, Clone, PartialEq)]
263pub struct Pattern {
264 pub node: Option<NodePattern>,
265 pub edge: Option<EdgePattern>,
266}
267
268#[derive(Debug, Clone, PartialEq)]
269pub struct NodePattern {
270 pub variable: Option<String>,
271 pub labels: Vec<String>,
272 pub properties: Vec<(String, Expression)>,
273}
274
275#[derive(Debug, Clone, PartialEq)]
276pub struct EdgePattern {
277 pub variable: Option<String>,
278 pub labels: Vec<String>,
279 pub direction: EdgeDirection,
280 pub properties: Vec<(String, Expression)>,
281 pub lower_bound: Option<u64>,
282 pub upper_bound: Option<u64>,
283}
284
285#[derive(Debug, Clone, PartialEq)]
286pub enum EdgeDirection {
287 LeftToRight,
288 RightToLeft,
289 Both,
290}
291
292impl ExplainStatement {
293 pub fn new(statement: Statement, explain_type: ExplainType) -> Self {
295 Self {
296 statement: Box::new(statement),
297 explain_type,
298 }
299 }
300}
301
302#[derive(Debug, Clone, PartialEq)]
304pub enum Expression {
305 Constant(Constant),
306 Variable(String),
307 Parameter(String),
309 PropertyAccess(Box<Expression>, String),
310 FunctionCall(String, Vec<Expression>),
311 BinaryOp(BinaryOp, Box<Expression>, Box<Expression>),
312 UnaryOp(UnaryOp, Box<Expression>),
313 List(Vec<Expression>),
314 Map(Vec<(String, Expression)>),
315 ExistsSubquery(Box<Query>),
317 Case(CaseExpr),
319 Star,
322 ListPredicate {
325 quantifier: Quantifier,
326 list: Box<Expression>,
327 var_name: String,
328 predicate: Box<Expression>,
329 },
330 Lambda {
333 var_name: String,
334 body: Box<Expression>,
335 },
336}
337
338#[derive(Debug, Clone, Copy, PartialEq)]
340pub enum Quantifier {
341 Any,
342 All,
343 None,
344 Single,
345}
346
347#[derive(Debug, Clone, PartialEq)]
349pub struct CaseAlternative {
350 pub when: Expression,
352 pub then: Expression,
354}
355
356#[derive(Debug, Clone, PartialEq)]
358pub struct CaseExpr {
359 pub subject: Option<Box<Expression>>,
361 pub alternatives: Vec<CaseAlternative>,
363 pub else_expr: Option<Box<Expression>>,
365}
366
367#[derive(Debug, Clone, PartialEq)]
368pub enum Constant {
369 Null,
370 Bool(bool),
371 Integer(i64),
372 Float(f64),
373 String(String),
374}
375
376#[derive(Debug, Clone, Copy, PartialEq)]
377pub enum BinaryOp {
378 Add,
379 Subtract,
380 Multiply,
381 Divide,
382 Modulo,
383 Equal,
384 NotEqual,
385 LessThan,
386 LessThanOrEqual,
387 GreaterThan,
388 GreaterThanOrEqual,
389 And,
390 Or,
391 Xor,
392 Concat,
393 In,
395 NotIn,
397 StartsWith,
399 EndsWith,
401 Contains,
403 Like,
405}
406
407#[derive(Debug, Clone, Copy, PartialEq)]
408pub enum UnaryOp {
409 Not,
410 Negate,
411 IsNull,
413 IsNotNull,
415}
416
417#[derive(Debug, Clone, PartialEq)]
419pub struct CreateNodeTable {
420 pub name: String,
421 pub columns: Vec<ColumnDef>,
422 pub primary_key: String,
423}
424
425#[derive(Debug, Clone, PartialEq)]
426pub struct CreateRelTable {
427 pub name: String,
428 pub from: String,
429 pub to: String,
430 pub columns: Vec<ColumnDef>,
431}
432
433#[derive(Debug, Clone, PartialEq)]
434pub struct DropTable {
435 pub name: String,
436}
437
438#[derive(Debug, Clone, PartialEq)]
440pub struct CreateIndex {
441 pub index_type: String,
442 pub index_name: String,
443 pub table_name: String,
444 pub variable: String,
445 pub property: String,
446 pub conflict_action: Option<String>,
447}
448
449#[derive(Debug, Clone, PartialEq)]
451pub struct DropIndex {
452 pub index_name: String,
453 pub table_name: String,
454}
455
456#[derive(Debug, Clone, PartialEq)]
458pub struct AlterTable {
459 pub table_name: String,
460 pub action: AlterAction,
461}
462
463#[derive(Debug, Clone, PartialEq)]
464pub enum AlterAction {
465 AddColumn { name: String, type_name: String },
466 DropColumn { name: String },
467 RenameColumn { old_name: String, new_name: String },
468 RenameTable { new_name: String },
469}
470
471#[derive(Debug, Clone, PartialEq)]
473pub struct UnionStatement {
474 pub left: Query,
475 pub right: Query,
476 pub all: bool,
477}
478
479#[derive(Debug, Clone, PartialEq)]
481pub struct CopyFrom {
482 pub table_name: String,
483 pub file_path: String,
484 pub options: std::collections::HashMap<String, String>,
485}
486
487#[derive(Debug, Clone, PartialEq)]
491pub struct CopyTo {
492 pub query: Query,
493 pub file_path: String,
494 pub format: CopyToFormat,
495 pub header: bool,
496}
497
498#[derive(Debug, Clone, PartialEq)]
499pub enum CopyToFormat {
500 Csv,
501 Parquet,
502}
503
504#[derive(Debug, Clone, PartialEq)]
506pub struct MergeStatement {
507 pub patterns: Vec<Pattern>,
508 pub on_create: Vec<SetItem>,
509 pub on_match: Vec<SetItem>,
510}
511
512#[derive(Debug, Clone, PartialEq)]
514pub struct StandaloneCall {
515 pub function_name: String,
516 pub args: Vec<Expression>,
517}
518
519#[derive(Debug, Clone, PartialEq)]
531pub struct CreateSequence {
532 pub name: String,
533 pub if_not_exists: bool,
534 pub or_replace: bool,
535 pub start_with: Option<i64>,
537 pub increment: Option<i64>,
539 pub min_value: Option<i64>,
541 pub max_value: Option<i64>,
543 pub cycle: Option<bool>,
545}
546
547#[derive(Debug, Clone, PartialEq)]
549pub struct DropSequence {
550 pub name: String,
551 pub if_exists: bool,
552}
553
554#[derive(Debug, Clone, PartialEq)]
563pub struct CreateMacro {
564 pub name: String,
566 pub positional_args: Vec<String>,
568 pub default_args: Vec<(String, Expression)>,
570 pub expression: Box<Expression>,
572}
573
574#[derive(Debug, Clone, PartialEq)]
576pub struct CreateVectorIndex {
577 pub index_name: String,
578 pub table_name: String,
579 pub column_name: String,
580 pub metric: String,
581 pub dimensions: u64,
582}
583
584#[derive(Debug, Clone, PartialEq)]
585pub struct ColumnDef {
586 pub name: String,
587 pub type_name: String,
588 pub compression: Option<String>,
589}
590
591#[derive(Debug, Clone, PartialEq)]
593pub struct CreateType {
594 pub name: String,
595 pub type_name: String,
596}
597
598#[derive(Debug, Clone, PartialEq)]
600pub struct CommentOnTable {
601 pub table_name: String,
602 pub comment: String,
603}
604
605#[derive(Debug, Clone, PartialEq)]
607pub struct CreateGraph {
608 pub name: String,
609 pub is_any: bool,
610}
611
612#[derive(Debug, Clone, PartialEq)]
614pub struct UseGraph {
615 pub name: String,
616}
617
618#[derive(Debug, Clone, PartialEq)]
620pub struct DropGraph {
621 pub name: String,
622}