#[derive(Debug, Clone, PartialEq)]
pub struct Query {
pub clauses: Vec<Clause>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Clause {
Match(MatchClause),
Return(ReturnClause),
Create(CreateClause),
Set(SetClause),
Remove(RemoveClause),
Delete(DeleteClause),
With(WithClause),
Merge(MergeClause),
Unwind(UnwindClause),
CreateIndex(CreateIndexClause),
DropIndex(DropIndexClause),
#[cfg(feature = "subgraph")]
CreateSnapshot(CreateSnapshotClause),
#[cfg(feature = "hypergraph")]
CreateHyperedge(CreateHyperedgeClause),
#[cfg(feature = "hypergraph")]
MatchHyperedge(MatchHyperedgeClause),
}
#[derive(Debug, Clone, PartialEq)]
pub enum TemporalPredicate {
AsOf(Expression),
Between(Expression, Expression),
}
#[derive(Debug, Clone, PartialEq)]
pub struct MatchClause {
pub optional: bool,
pub pattern: Pattern,
pub temporal_predicate: Option<TemporalPredicate>,
pub where_clause: Option<Expression>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ReturnClause {
pub distinct: bool,
pub items: Vec<ReturnItem>,
pub order_by: Option<Vec<OrderItem>>,
pub skip: Option<Expression>,
pub limit: Option<Expression>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ReturnItem {
pub expr: Expression,
pub alias: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct OrderItem {
pub expr: Expression,
pub ascending: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateClause {
pub pattern: Pattern,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SetClause {
pub items: Vec<SetItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum SetItem {
Property {
target: Expression,
value: Expression,
},
}
#[derive(Debug, Clone, PartialEq)]
pub struct RemoveClause {
pub items: Vec<RemoveItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum RemoveItem {
Property(Expression),
Label {
variable: String,
label: String,
},
}
#[derive(Debug, Clone, PartialEq)]
pub struct DeleteClause {
pub detach: bool,
pub exprs: Vec<Expression>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WithClause {
pub distinct: bool,
pub items: Vec<ReturnItem>,
pub where_clause: Option<Expression>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct MergeClause {
pub pattern: Pattern,
pub on_match: Vec<SetItem>,
pub on_create: Vec<SetItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct UnwindClause {
pub expr: Expression,
pub variable: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum IndexTarget {
NodeLabel(String),
RelationshipType(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateIndexClause {
pub name: Option<String>,
pub target: IndexTarget,
pub property: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DropIndexClause {
pub name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Pattern {
pub chains: Vec<PatternChain>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PatternChain {
pub elements: Vec<PatternElement>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum PatternElement {
Node(NodePattern),
Relationship(RelationshipPattern),
}
#[derive(Debug, Clone, PartialEq)]
pub struct NodePattern {
pub variable: Option<String>,
pub labels: Vec<String>,
pub properties: Option<MapLiteral>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RelationshipPattern {
pub variable: Option<String>,
pub rel_types: Vec<String>,
pub direction: RelDirection,
pub properties: Option<MapLiteral>,
pub min_hops: Option<u32>,
pub max_hops: Option<u32>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RelDirection {
Outgoing,
Incoming,
Undirected,
}
pub type MapLiteral = Vec<(String, Expression)>;
#[derive(Debug, Clone, PartialEq)]
pub enum Expression {
Literal(Literal),
Variable(String),
Property(Box<Expression>, String),
Parameter(String),
BinaryOp(BinaryOp, Box<Expression>, Box<Expression>),
UnaryOp(UnaryOp, Box<Expression>),
FunctionCall {
name: String,
distinct: bool,
args: Vec<Expression>,
},
IsNull(Box<Expression>, bool),
CountStar,
ListLiteral(Vec<Expression>),
#[cfg(feature = "hypergraph")]
TemporalRef {
node: Box<Expression>,
timestamp: Box<Expression>,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum Literal {
Integer(i64),
Float(f64),
String(String),
Bool(bool),
Null,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinaryOp {
Add,
Sub,
Mul,
Div,
Mod,
Eq,
Neq,
Lt,
Lte,
Gt,
Gte,
And,
Or,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UnaryOp {
Not,
Neg,
}
#[cfg(feature = "subgraph")]
#[derive(Debug, Clone, PartialEq)]
pub struct CreateSnapshotClause {
pub variable: Option<String>,
pub labels: Vec<String>,
pub properties: Option<MapLiteral>,
pub temporal_anchor: Option<Expression>,
pub from_match: MatchClause,
pub from_return: Vec<ReturnItem>,
}
#[cfg(feature = "hypergraph")]
#[derive(Debug, Clone, PartialEq)]
pub struct CreateHyperedgeClause {
pub variable: Option<String>,
pub labels: Vec<String>,
pub sources: Vec<Expression>,
pub targets: Vec<Expression>,
}
#[cfg(feature = "hypergraph")]
#[derive(Debug, Clone, PartialEq)]
pub struct MatchHyperedgeClause {
pub variable: Option<String>,
pub labels: Vec<String>,
}