linkrs_query/parser/ast/stmt/
dml.rs1use crate::parser::ast::pattern::Pattern;
2use linkrs_core::types::expr::contextual::ContextualExpression;
3use linkrs_core::types::Span;
4
5use super::YieldClause;
6
7#[derive(Debug, Clone, PartialEq)]
8pub struct DeleteStmt {
9 pub span: Span,
10 pub target: DeleteTarget,
11 pub with_edge: bool,
12 pub detach: bool,
13}
14
15impl DeleteStmt {
16 pub fn new(target: DeleteTarget, span: Span) -> Self {
17 Self {
18 span,
19 target,
20 with_edge: false,
21 detach: false,
22 }
23 }
24
25 pub fn with_edge(mut self, with_edge: bool) -> Self {
26 self.with_edge = with_edge;
27 self
28 }
29
30 pub fn with_detach(mut self, detach: bool) -> Self {
31 self.detach = detach;
32 self
33 }
34}
35
36#[derive(Debug, Clone, PartialEq)]
37pub enum DeleteTarget {
38 Vertices {
39 tag: String,
40 vids: Vec<ContextualExpression>,
41 },
42 Edges {
43 edge_type: Option<String>,
44 edges: Vec<(
45 ContextualExpression,
46 ContextualExpression,
47 Option<ContextualExpression>,
48 )>,
49 },
50 Index(String),
51}
52
53#[derive(Debug, Clone, PartialEq)]
54pub struct UpdateStmt {
55 pub span: Span,
56 pub target: UpdateTarget,
57 pub set_clause: SetClause,
58 pub where_clause: Option<ContextualExpression>,
59 pub is_upsert: bool,
60 pub yield_clause: Option<YieldClause>,
61}
62
63#[derive(Debug, Clone, PartialEq)]
64pub enum UpdateTarget {
65 Vertex(ContextualExpression),
66 Edge {
67 src: ContextualExpression,
68 dst: ContextualExpression,
69 edge_type: Option<String>,
70 rank: Option<ContextualExpression>,
71 },
72 Tag(String),
73 TagOnVertex {
74 vid: Box<ContextualExpression>,
75 tag_name: String,
76 },
77}
78
79#[derive(Debug, Clone, PartialEq)]
80pub struct SetClause {
81 pub span: Span,
82 pub assignments: Vec<Assignment>,
83}
84
85#[derive(Debug, Clone, PartialEq)]
86pub struct Assignment {
87 pub property: String,
88 pub value: ContextualExpression,
89 pub target: Option<ContextualExpression>,
90 pub object: Option<ContextualExpression>,
91 pub is_map_overwrite: bool,
92}
93
94#[derive(Debug, Clone, PartialEq)]
95pub struct InsertStmt {
96 pub span: Span,
97 pub target: InsertTarget,
98 pub if_not_exists: bool,
99}
100
101#[derive(Debug, Clone, PartialEq)]
102pub enum InsertTarget {
103 Vertices {
104 tag: TagInsertSpec,
105 values: Vec<VertexRow>,
106 },
107 Edge {
108 edge_name: String,
109 prop_names: Vec<String>,
110 edges: Vec<(
111 ContextualExpression,
112 ContextualExpression,
113 Option<ContextualExpression>,
114 Vec<ContextualExpression>,
115 )>,
116 },
117}
118
119#[derive(Debug, Clone, PartialEq)]
120pub struct TagInsertSpec {
121 pub tag_name: String,
122 pub prop_names: Vec<String>,
123 pub is_default_props: bool,
124}
125
126#[derive(Debug, Clone, PartialEq)]
127pub struct VertexRow {
128 pub vid: ContextualExpression,
129 pub values: Vec<ContextualExpression>,
130}
131
132#[derive(Debug, Clone, PartialEq)]
133pub struct MergeStmt {
134 pub span: Span,
135 pub pattern: Pattern,
136 pub on_create: Option<SetClause>,
137 pub on_match: Option<SetClause>,
138}
139
140#[derive(Debug, Clone, PartialEq)]
141pub struct SetStmt {
142 pub span: Span,
143 pub assignments: Vec<Assignment>,
144}
145
146#[derive(Debug, Clone, PartialEq)]
147pub struct RemoveStmt {
148 pub span: Span,
149 pub items: Vec<ContextualExpression>,
150}
151
152#[derive(Debug, Clone, PartialEq)]
153pub struct CopyStmt {
154 pub span: Span,
155 pub target: CopyTarget,
156 pub direction: CopyDirection,
158 pub file_paths: Vec<String>,
159 pub by_column: bool,
160 pub header: bool,
161 pub delimiter: char,
162 pub batch_size: Option<usize>,
163}
164
165#[derive(Debug, Clone, Copy, PartialEq, Eq)]
166pub enum CopyDirection {
167 From,
169 To,
171}
172
173#[derive(Debug, Clone, PartialEq)]
174pub enum CopyTarget {
175 Vertex(String),
176 Edge(String),
177}