use crate::filter::Filter;
#[derive(Debug, Clone)]
pub struct TqlQuery {
pub explain: bool,
pub entry: QueryEntry,
pub predicate: Option<Predicate>,
pub returns: ReturnClause,
pub order_by: Vec<OrderExpr>,
pub limit: Option<usize>,
pub offset: Option<usize>,
}
#[derive(Debug, Clone)]
pub enum QueryEntry {
Match { pattern: TqlPattern },
OptionalMatch { pattern: TqlPattern },
Find { filter: Filter },
Search {
vector: Vec<f64>,
top_k: usize,
expand: Option<ExpandClause>,
},
}
#[derive(Debug, Clone)]
pub struct TqlPattern {
pub nodes: Vec<TqlNodePattern>,
pub edges: Vec<TqlEdgePattern>,
}
#[derive(Debug, Clone)]
pub struct TqlNodePattern {
pub var: Option<String>,
pub filter: Option<Filter>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EdgeDirection {
Forward,
Backward,
Both,
}
#[derive(Debug, Clone)]
pub struct TqlEdgePattern {
pub labels: Vec<String>,
pub hop_range: Option<HopRange>,
pub direction: EdgeDirection,
}
#[derive(Debug, Clone, Copy)]
pub struct HopRange {
pub min: usize,
pub max: usize,
}
#[derive(Debug, Clone)]
pub struct ExpandClause {
pub labels: Vec<String>,
pub min_depth: usize,
pub max_depth: usize,
}
#[derive(Debug, Clone)]
pub enum Predicate {
Compare {
left: TqlExpr,
op: TqlCompOp,
right: TqlExpr,
},
DocFilter {
var: Option<String>,
filter: Filter,
},
And(Box<Predicate>, Box<Predicate>),
Or(Box<Predicate>, Box<Predicate>),
Not(Box<Predicate>),
}
#[derive(Debug, Clone)]
pub enum TqlExpr {
Property { var: String, field: String },
Literal(TqlLiteral),
}
#[derive(Debug, Clone)]
pub enum TqlLiteral {
Int(i64),
Float(f64),
Str(String),
Bool(bool),
Null,
}
#[derive(Debug, Clone, Copy)]
pub enum TqlCompOp {
Eq, Ne, Gt, Gte, Lt, Lte, }
#[derive(Debug, Clone)]
pub enum ReturnClause {
All,
Variables(Vec<String>),
Expressions(Vec<ReturnExpr>),
}
#[derive(Debug, Clone)]
pub struct ReturnExpr {
pub kind: ReturnExprKind,
pub alias: Option<String>,
pub distinct: bool,
}
#[derive(Debug, Clone)]
pub enum ReturnExprKind {
Var(String),
Property(String, String),
Aggregate(AggFunc, Box<ReturnExprKind>),
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum AggFunc {
Count,
Sum,
Avg,
Min,
Max,
Collect,
}
#[derive(Debug, Clone)]
pub struct OrderExpr {
pub expr: TqlExpr,
pub descending: bool,
}
#[derive(Debug, Clone)]
pub enum TqlStatement {
Query(TqlQuery),
Mutation(TqlMutation),
}
#[derive(Debug, Clone)]
pub struct TqlMutation {
pub source: Option<MutationSource>,
pub action: MutationAction,
}
#[derive(Debug, Clone)]
pub struct MutationSource {
pub pattern: TqlPattern,
pub predicate: Option<Predicate>,
}
#[derive(Debug, Clone)]
pub enum MutationAction {
Create(CreateAction),
Set(Vec<SetAssignment>),
Delete { vars: Vec<String>, detach: bool },
}
#[derive(Debug, Clone)]
pub struct CreateAction {
pub nodes: Vec<CreateNode>,
pub edges: Vec<CreateEdge>,
}
#[derive(Debug, Clone)]
pub struct CreateNode {
pub var: Option<String>,
pub payload: serde_json::Value,
}
#[derive(Debug, Clone)]
pub struct CreateEdge {
pub src_var: String,
pub dst_var: String,
pub label: String,
pub weight: f32,
}
#[derive(Debug, Clone)]
pub struct SetAssignment {
pub var: String,
pub field: String,
pub value: serde_json::Value,
}