Skip to main content

linkrs_query/binder/bound/
stmt_dml.rs

1use crate::parser::ast::{CopyDirection, CopyTarget, TagInsertSpec};
2
3use linkrs_core::types::EdgeDirection;
4
5use super::expr::BoundExpression;
6
7#[derive(Debug, Clone)]
8pub struct BoundInsert {
9    pub target: BoundInsertTarget,
10    pub if_not_exists: bool,
11}
12
13#[derive(Debug, Clone)]
14pub enum BoundInsertTarget {
15    Vertices {
16        tag: TagInsertSpec,
17        values: Vec<BoundVertexRow>,
18    },
19    Edge {
20        edge_name: String,
21        prop_names: Vec<String>,
22        edges: Vec<(
23            BoundExpression,
24            BoundExpression,
25            Option<BoundExpression>,
26            Vec<BoundExpression>,
27        )>,
28    },
29}
30
31#[derive(Debug, Clone)]
32pub struct BoundVertexRow {
33    pub vid: BoundExpression,
34    pub values: Vec<BoundExpression>,
35}
36
37#[derive(Debug, Clone)]
38pub struct BoundUpdate {
39    pub target: BoundUpdateTarget,
40    pub assignments: Vec<BoundAssignment>,
41    pub where_clause: Option<BoundExpression>,
42    pub is_upsert: bool,
43}
44
45#[derive(Debug, Clone)]
46pub enum BoundUpdateTarget {
47    Vertex(BoundExpression),
48    Edge(Box<BoundEdgeUpdateTarget>),
49    Tag(String),
50    TagOnVertex {
51        vid: BoundExpression,
52        tag_name: String,
53    },
54}
55
56/// Edge update target payload. Boxed inside [`BoundUpdateTarget::Edge`] so the
57/// several large `BoundExpression` fields do not inflate every enum variant.
58#[derive(Debug, Clone)]
59pub struct BoundEdgeUpdateTarget {
60    pub src: BoundExpression,
61    pub dst: BoundExpression,
62    pub edge_type: Option<String>,
63    pub rank: Option<BoundExpression>,
64}
65
66#[derive(Debug, Clone)]
67pub struct BoundAssignment {
68    pub property: String,
69    pub value: BoundExpression,
70    pub target: Option<BoundExpression>,
71    pub object: Option<BoundExpression>,
72    pub is_map_overwrite: bool,
73}
74
75#[derive(Debug, Clone)]
76pub struct BoundDelete {
77    pub target: BoundDeleteTarget,
78    pub with_edge: bool,
79    pub detach: bool,
80}
81
82#[derive(Debug, Clone)]
83pub enum BoundDeleteTarget {
84    Vertices {
85        tag: String,
86        ids: Vec<BoundExpression>,
87    },
88    Edges {
89        edge_type: Option<String>,
90        edges: Vec<(BoundExpression, BoundExpression, Option<BoundExpression>)>,
91    },
92    Index(String),
93}
94
95// ── Bound pattern types (replace raw AST patterns) ───────────────────────────
96
97#[derive(Debug, Clone)]
98pub struct BoundPatternVertex {
99    pub variable: Option<String>,
100    pub labels: Vec<String>,
101    pub properties: Option<Vec<(String, BoundExpression)>>,
102}
103
104#[derive(Debug, Clone)]
105pub struct BoundPatternEdge {
106    pub variable: Option<String>,
107    pub edge_types: Vec<String>,
108    pub properties: Option<Vec<(String, BoundExpression)>>,
109    pub direction: EdgeDirection,
110}
111
112#[derive(Debug, Clone)]
113pub enum BoundMergePattern {
114    Node(BoundPatternVertex),
115    Edge {
116        src: BoundPatternVertex,
117        edge: BoundPatternEdge,
118        dst: BoundPatternVertex,
119    },
120}
121
122#[derive(Debug, Clone)]
123pub struct BoundMerge {
124    pub pattern: BoundMergePattern,
125    pub on_create: Vec<BoundAssignment>,
126    pub on_match: Vec<BoundAssignment>,
127}
128
129#[derive(Debug, Clone)]
130pub struct BoundSet {
131    pub assignments: Vec<BoundAssignment>,
132}
133
134#[derive(Debug, Clone)]
135pub struct BoundRemove {
136    pub items: Vec<BoundExpression>,
137}
138
139#[derive(Debug, Clone)]
140pub struct BoundCopy {
141    pub target: CopyTarget,
142    pub direction: CopyDirection,
143    pub file_paths: Vec<String>,
144    pub by_column: bool,
145    pub header: bool,
146    pub delimiter: char,
147    pub batch_size: Option<usize>,
148}