use crate::types::Value;
#[derive(Debug, Clone)]
pub enum Statement {
Match(MatchStatement),
OptionalMatch(MatchStatement),
MatchOptionalMatch(MatchOptionalMatchStatement),
Unwind(UnwindStatement),
Union(UnionStatement),
MatchWith(MatchWithStatement),
Insert(InsertStatement),
MatchInsert(MatchInsertStatement),
Set(SetStatement),
Remove(RemoveStatement),
Delete(DeleteStatement),
CreateIndex(CreateIndexStatement),
DropIndex(DropIndexStatement),
ShowIndexes,
Call(CallStatement),
CallPipeline(CallPipelineStatement),
Truncate,
LoadCsvNodes(LoadCsvNodesStatement),
LoadCsvEdges(LoadCsvEdgesStatement),
UnwindInsert(UnwindInsertStatement),
Constraint(ConstraintStatement),
}
#[derive(Debug, Clone)]
pub struct CallPipelineStatement {
pub name: String,
pub params: Vec<(String, Expr)>,
pub yields: Vec<String>,
pub match_clause: Option<CallPipelineMatch>,
pub return_clause: ReturnClause,
}
#[derive(Debug, Clone)]
pub struct CallPipelineMatch {
pub patterns: Vec<GraphPattern>,
pub where_clause: Option<Expr>,
pub path_mode: PathMode,
}
#[derive(Debug, Clone)]
pub struct CallStatement {
pub name: String,
pub params: Vec<(String, Expr)>,
pub yields: Option<Vec<String>>,
}
#[derive(Debug, Clone)]
pub struct UnwindStatement {
pub expr: Expr,
pub variable: String,
pub return_clause: ReturnClause,
}
#[derive(Debug, Clone)]
pub struct UnionStatement {
pub branches: Vec<Statement>,
pub all: bool,
}
#[derive(Debug, Clone)]
pub struct WithClause {
pub distinct: bool,
pub items: Vec<ReturnItem>,
pub where_clause: Option<Expr>,
}
#[derive(Debug, Clone)]
pub struct MatchWithStatement {
pub patterns: Vec<GraphPattern>,
pub where_clause: Option<Expr>,
pub path_mode: PathMode,
pub with_clause: WithClause,
pub return_clause: ReturnClause,
}
#[derive(Debug, Clone)]
pub struct OptionalMatchClause {
pub patterns: Vec<GraphPattern>,
pub where_clause: Option<Expr>,
pub path_mode: PathMode,
}
#[derive(Debug, Clone)]
pub struct MatchOptionalMatchStatement {
pub patterns: Vec<GraphPattern>,
pub where_clause: Option<Expr>,
pub path_mode: PathMode,
pub optional_clauses: Vec<OptionalMatchClause>,
pub return_clause: ReturnClause,
}
#[derive(Debug, Clone)]
pub struct CreateIndexStatement {
pub label: String,
pub property: String,
}
#[derive(Debug, Clone)]
pub struct DropIndexStatement {
pub label: String,
pub property: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum PathMode {
#[default]
Walk,
Trail,
Simple,
}
#[derive(Debug, Clone)]
pub struct PathQuantifier {
pub min: u32,
pub max: Option<u32>,
}
#[derive(Debug, Clone)]
pub struct MatchStatement {
pub patterns: Vec<GraphPattern>,
pub where_clause: Option<Expr>,
pub return_clause: ReturnClause,
pub path_mode: PathMode,
}
#[derive(Debug, Clone)]
pub struct GraphPattern {
pub start: NodePattern,
pub steps: Vec<EdgePatternStep>,
}
#[derive(Debug, Clone)]
pub struct NodePattern {
pub variable: Option<String>,
pub labels: Vec<String>,
pub properties: Vec<PropertyConstraint>,
}
#[derive(Debug, Clone)]
pub struct EdgePatternStep {
pub edge: EdgePattern,
pub node: NodePattern,
}
#[derive(Debug, Clone)]
pub struct EdgePattern {
pub variable: Option<String>,
pub label: Option<String>,
pub properties: Vec<PropertyConstraint>,
pub direction: EdgeDirection,
pub quantifier: Option<PathQuantifier>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EdgeDirection {
Outgoing,
Incoming,
Either,
}
#[derive(Debug, Clone)]
pub struct PropertyConstraint {
pub key: String,
pub value: Expr,
}
#[derive(Debug, Clone)]
pub struct ReturnClause {
pub distinct: bool,
pub items: Vec<ReturnItem>,
pub order_by: Vec<OrderByItem>,
pub limit: Option<Expr>,
pub offset: Option<Expr>,
}
#[derive(Debug, Clone)]
pub struct ReturnItem {
pub expr: Expr,
pub alias: Option<String>,
}
#[derive(Debug, Clone)]
pub struct OrderByItem {
pub expr: Expr,
pub ascending: bool,
}
#[derive(Debug, Clone)]
pub struct MatchInsertStatement {
pub patterns: Vec<GraphPattern>,
pub where_clause: Option<Expr>,
pub elements: Vec<InsertElement>,
}
#[derive(Debug, Clone)]
pub struct InsertStatement {
pub elements: Vec<InsertElement>,
}
#[derive(Debug, Clone)]
pub enum InsertElement {
Node(InsertNode),
Edge(InsertEdge),
}
#[derive(Debug, Clone)]
pub struct InsertNode {
pub variable: Option<String>,
pub labels: Vec<String>,
pub properties: Vec<PropertyAssignment>,
}
#[derive(Debug, Clone)]
pub struct InsertEdge {
pub from_var: String,
pub to_var: String,
pub label: String,
pub properties: Vec<PropertyAssignment>,
pub directed: bool,
}
#[derive(Debug, Clone)]
pub struct PropertyAssignment {
pub key: String,
pub value: Expr,
}
#[derive(Debug, Clone)]
pub struct SetStatement {
pub match_pattern: GraphPattern,
pub where_clause: Option<Expr>,
pub assignments: Vec<SetItem>,
}
#[derive(Debug, Clone)]
pub enum SetItem {
Property { variable: String, key: String, value: Expr },
AddLabel { variable: String, label: String },
}
#[derive(Debug, Clone)]
pub struct RemoveStatement {
pub match_pattern: GraphPattern,
pub where_clause: Option<Expr>,
pub items: Vec<RemoveItem>,
}
#[derive(Debug, Clone)]
pub enum RemoveItem {
Property { variable: String, key: String },
Label { variable: String, label: String },
}
#[derive(Debug, Clone)]
pub struct DeleteStatement {
pub match_pattern: GraphPattern,
pub where_clause: Option<Expr>,
pub variables: Vec<String>,
pub detach: bool,
}
#[derive(Debug, Clone)]
pub struct LoadCsvNodesStatement {
pub path: String,
pub label: Option<String>,
}
#[derive(Debug, Clone)]
pub struct LoadCsvEdgesStatement {
pub path: String,
pub label: Option<String>,
}
#[derive(Debug, Clone)]
pub enum Expr {
Literal(Value),
Var(String),
Property(Box<Expr>, String),
BinOp(Box<Expr>, BinOp, Box<Expr>),
Not(Box<Expr>),
IsNull(Box<Expr>, bool),
Call(String, Vec<Expr>),
List(Vec<Expr>),
Star,
Param(String),
}
#[derive(Debug, Clone)]
pub struct UnwindInsertStatement {
pub expr: Expr,
pub variable: String,
pub elements: Vec<InsertElement>,
}
#[derive(Debug, Clone)]
pub struct ConstraintStatement {
pub op: ConstraintOp,
}
#[derive(Debug, Clone)]
pub enum ConstraintOp {
Create {
kind: ConstraintKind,
label: String,
property: String,
},
Drop {
kind: ConstraintKind,
label: String,
property: String,
},
Show,
}
#[derive(Debug, Clone)]
pub enum ConstraintKind {
Unique,
Type(ValueKind),
}
#[derive(Debug, Clone)]
pub enum ValueKind {
Integer,
Float,
String,
Boolean,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinOp {
And,
Or,
Eq,
Neq,
Lt,
Lte,
Gt,
Gte,
Add,
Sub,
Mul,
Div,
Mod,
In,
}