velesdb_core/velesql/
graph_pattern.rs1use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8use super::ast::{Condition, Value};
9
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12pub struct MatchClause {
13 pub patterns: Vec<GraphPattern>,
15 pub where_clause: Option<Condition>,
17 pub return_clause: ReturnClause,
19}
20
21#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
23pub struct GraphPattern {
24 pub name: Option<String>,
26 pub nodes: Vec<NodePattern>,
28 pub relationships: Vec<RelationshipPattern>,
30}
31
32#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
34pub struct NodePattern {
35 pub alias: Option<String>,
37 pub labels: Vec<String>,
39 pub properties: HashMap<String, Value>,
41 #[serde(default, skip_serializing_if = "Option::is_none")]
49 pub collection: Option<String>,
50}
51
52impl NodePattern {
53 #[must_use]
55 pub fn new() -> Self {
56 Self {
57 alias: None,
58 labels: Vec::new(),
59 properties: HashMap::new(),
60 collection: None,
61 }
62 }
63
64 #[must_use]
66 pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
67 self.alias = Some(alias.into());
68 self
69 }
70
71 #[must_use]
73 pub fn with_label(mut self, label: impl Into<String>) -> Self {
74 self.labels.push(label.into());
75 self
76 }
77
78 #[must_use]
80 pub fn with_collection(mut self, collection: impl Into<String>) -> Self {
81 self.collection = Some(collection.into());
82 self
83 }
84}
85
86impl Default for NodePattern {
87 fn default() -> Self {
88 Self::new()
89 }
90}
91
92#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
94pub struct RelationshipPattern {
95 pub alias: Option<String>,
97 pub types: Vec<String>,
99 pub direction: Direction,
101 pub range: Option<(u32, u32)>,
103 pub properties: HashMap<String, Value>,
105}
106
107impl RelationshipPattern {
108 #[must_use]
110 pub fn new(direction: Direction) -> Self {
111 Self {
112 alias: None,
113 types: Vec::new(),
114 direction,
115 range: None,
116 properties: HashMap::new(),
117 }
118 }
119}
120
121#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
123#[non_exhaustive]
124pub enum Direction {
125 Outgoing,
127 Incoming,
129 Both,
131}
132
133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
135pub struct ReturnClause {
136 pub items: Vec<ReturnItem>,
138 pub order_by: Option<Vec<OrderByItem>>,
140 pub limit: Option<u64>,
142}
143
144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
146pub struct ReturnItem {
147 pub expression: String,
149 pub alias: Option<String>,
151}
152
153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
155pub struct OrderByItem {
156 pub expr: crate::velesql::OrderByExpr,
161 pub descending: bool,
163}