velesdb_core/velesql/ast/dml.rs
1//! DML statement types for VelesQL.
2//!
3//! This module defines INSERT/UPDATE/DELETE and graph mutation AST nodes.
4
5use serde::{Deserialize, Serialize};
6
7use super::{Condition, Value};
8
9/// INSERT or UPSERT statement (supports multi-row).
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11pub struct InsertStatement {
12 /// Target collection name.
13 pub table: String,
14 /// Target columns.
15 pub columns: Vec<String>,
16 /// Rows of values; each row corresponds to `columns`.
17 ///
18 /// **Breaking change from v3.4**: type changed from `Vec<Value>` (single
19 /// row) to `Vec<Vec<Value>>` (multi-row). No backward-compatible
20 /// deserialization — the plan cache is in-memory (`Instant`-keyed) so
21 /// no persistent data uses this format.
22 pub rows: Vec<Vec<Value>>,
23}
24
25/// UPDATE assignment.
26#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
27pub struct UpdateAssignment {
28 /// Column name to update.
29 pub column: String,
30 /// Assigned value expression.
31 pub value: Value,
32}
33
34/// UPDATE statement.
35#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
36pub struct UpdateStatement {
37 /// Target collection name.
38 pub table: String,
39 /// SET assignments.
40 pub assignments: Vec<UpdateAssignment>,
41 /// Optional WHERE clause.
42 pub where_clause: Option<Condition>,
43}
44
45/// INSERT EDGE statement (VelesQL v3.3).
46#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
47pub struct InsertEdgeStatement {
48 /// Target graph collection name.
49 pub collection: String,
50 /// Optional explicit edge ID.
51 pub edge_id: Option<u64>,
52 /// Source node ID.
53 pub source: u64,
54 /// Target node ID.
55 pub target: u64,
56 /// Edge label/type.
57 pub label: String,
58 /// Optional edge properties.
59 pub properties: Vec<(String, Value)>,
60}
61
62/// DELETE FROM statement (VelesQL v3.3).
63#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
64pub struct DeleteStatement {
65 /// Target collection name.
66 pub table: String,
67 /// WHERE clause (mandatory — prevents accidental full deletion).
68 pub where_clause: Condition,
69}
70
71/// DELETE EDGE statement (VelesQL v3.3).
72#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
73pub struct DeleteEdgeStatement {
74 /// Target graph collection name.
75 pub collection: String,
76 /// Edge ID to delete.
77 pub edge_id: u64,
78}
79
80/// SELECT EDGES statement (VelesQL v3.5 Phase 5).
81///
82/// Queries edges from a graph collection with optional filtering
83/// by source node, target node, or edge label.
84#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
85pub struct SelectEdgesStatement {
86 /// Target graph collection name.
87 pub collection: String,
88 /// Optional WHERE clause for filtering (source=N, target=N, label='X').
89 pub where_clause: Option<Condition>,
90 /// Optional LIMIT clause.
91 pub limit: Option<u64>,
92}
93
94/// INSERT NODE statement (VelesQL v3.5 Phase 5).
95///
96/// Inserts or updates a node payload in a graph collection.
97#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
98pub struct InsertNodeStatement {
99 /// Target graph collection name.
100 pub collection: String,
101 /// Node ID.
102 pub node_id: u64,
103 /// JSON payload for the node.
104 pub payload: serde_json::Value,
105}
106
107/// DML statement.
108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
109#[non_exhaustive]
110pub enum DmlStatement {
111 /// INSERT statement.
112 Insert(InsertStatement),
113 /// UPSERT statement (VelesQL v3.5 Phase 4).
114 Upsert(InsertStatement),
115 /// UPDATE statement.
116 Update(UpdateStatement),
117 /// INSERT EDGE statement (VelesQL v3.3).
118 InsertEdge(InsertEdgeStatement),
119 /// DELETE FROM statement (VelesQL v3.3).
120 Delete(DeleteStatement),
121 /// DELETE EDGE statement (VelesQL v3.3).
122 DeleteEdge(DeleteEdgeStatement),
123 /// SELECT EDGES statement (VelesQL v3.5 Phase 5).
124 SelectEdges(SelectEdgesStatement),
125 /// INSERT NODE statement (VelesQL v3.5 Phase 5).
126 InsertNode(InsertNodeStatement),
127}