linkrs_query/binder/bound/
stmt.rs1use crate::parser::ast::Stmt;
2
3use super::stmt_ddl::*;
4use super::stmt_dml::*;
5use super::stmt_dql::*;
6
7#[derive(Debug, Clone)]
9pub enum BoundStatement {
10 Match(BoundMatchStatement),
12 Go(BoundGoStatement),
13 Lookup(BoundLookupStatement),
14 FetchVertices(BoundFetchVerticesStatement),
15 FetchEdges(BoundFetchEdgesStatement),
16 FindPath(BoundFindPathStatement),
17 Subgraph(BoundSubgraphStatement),
18
19 Pipe(BoundPipeStatement),
21 Return(BoundReturnStatement),
22 With(BoundWithStatement),
23 Unwind(BoundUnwindStatement),
24 GroupBy(BoundGroupByStatement),
25 SetOperation(BoundSetOperationStatement),
26 Filter(BoundFilter),
27 Yield(BoundYield),
28 Collect(BoundCollect),
29 AssignVariable(BoundAssignVariable),
30
31 Insert(BoundInsert),
33 Update(BoundUpdate),
34 Delete(BoundDelete),
35 Merge(BoundMerge),
36 Set(BoundSet),
37 Remove(BoundRemove),
38 Copy(BoundCopy),
39
40 Drop(BoundDrop),
42 Alter(BoundAlter),
43 Show(BoundShow),
44 ShowCreate(BoundShowCreate),
45 Desc(BoundDesc),
46 ClearSpace(BoundClearSpace),
47 CreateUser(BoundCreateUser),
48 DropUser(BoundDropUser),
49 AlterUser(BoundAlterUser),
50 CreateFulltextIndex(BoundCreateFulltextIndex),
51 CreateVectorIndex(BoundCreateVectorIndex),
52
53 Explain(BoundExplain),
55 Profile(BoundProfile),
56
57 Use(BoundUse),
59
60 BeginTransaction(BoundBeginTransaction),
62 Commit(BoundCommit),
63 Rollback(BoundRollback),
64 Savepoint(BoundSavepoint),
65 ReleaseSavepoint(BoundReleaseSavepoint),
66
67 Assignment(BoundAssignmentStatement),
69
70 Other(Box<Stmt>),
72}
73
74impl BoundStatement {
75 pub fn kind(&self) -> &str {
76 match self {
77 Self::Match(_) => "Match",
78 Self::Go(_) => "Go",
79 Self::Lookup(_) => "Lookup",
80 Self::FetchVertices(_) => "FetchVertices",
81 Self::FetchEdges(_) => "FetchEdges",
82 Self::FindPath(_) => "FindPath",
83 Self::Subgraph(_) => "Subgraph",
84 Self::Pipe(_) => "Pipe",
85 Self::Return(_) => "Return",
86 Self::With(_) => "With",
87 Self::Unwind(_) => "Unwind",
88 Self::GroupBy(_) => "GroupBy",
89 Self::SetOperation(_) => "SetOperation",
90 Self::Filter(_) => "Filter",
91 Self::Yield(_) => "Yield",
92 Self::Collect(_) => "Collect",
93 Self::AssignVariable(_) => "AssignVariable",
94 Self::Insert(_) => "Insert",
95 Self::Update(_) => "Update",
96 Self::Delete(_) => "Delete",
97 Self::Merge(_) => "Merge",
98 Self::Set(_) => "Set",
99 Self::Remove(_) => "Remove",
100 Self::Copy(_) => "Copy",
101 Self::Drop(_) => "Drop",
102 Self::Alter(_) => "Alter",
103 Self::Show(_) => "Show",
104 Self::ShowCreate(_) => "ShowCreate",
105 Self::Desc(_) => "Desc",
106 Self::ClearSpace(_) => "ClearSpace",
107 Self::CreateUser(_) => "CreateUser",
108 Self::DropUser(_) => "DropUser",
109 Self::AlterUser(_) => "AlterUser",
110 Self::CreateFulltextIndex(_) => "CreateFulltextIndex",
111 Self::CreateVectorIndex(_) => "CreateVectorIndex",
112 Self::Explain(_) => "Explain",
113 Self::Profile(_) => "Profile",
114 Self::Use(_) => "Use",
115 Self::BeginTransaction(s) => match s.read_only {
116 Some(true) => "BeginTransactionReadOnly",
117 Some(false) => "BeginTransactionReadWrite",
118 None => "BeginTransaction",
119 },
120 Self::Commit(_) => "Commit",
121 Self::Rollback(s) => {
122 if s.savepoint_name.is_some() {
123 "RollbackToSavepoint"
124 } else {
125 "Rollback"
126 }
127 }
128 Self::Savepoint(_) => "Savepoint",
129 Self::ReleaseSavepoint(_) => "ReleaseSavepoint",
130 Self::Assignment(_) => "Assignment",
131 Self::Other(stmt) => stmt.kind(),
132 }
133 }
134
135 pub fn as_match(&self) -> Option<&BoundMatchStatement> {
136 if let Self::Match(v) = self {
137 Some(v)
138 } else {
139 None
140 }
141 }
142
143 pub fn as_go(&self) -> Option<&BoundGoStatement> {
144 if let Self::Go(v) = self {
145 Some(v)
146 } else {
147 None
148 }
149 }
150}