pub const NOW_PARAM_NAME: &str = "__nanograph_now"; #[derive(Debug, Clone)] pub struct QueryFile { pub queries: Vec, } #[derive(Debug, Clone)] pub struct QueryDecl { pub name: String, pub description: Option, pub instruction: Option, pub params: Vec, pub match_clause: Vec, pub return_clause: Vec, pub order_clause: Vec, pub limit: Option, pub mutations: Vec, } #[derive(Debug, Clone)] pub struct Param { pub name: String, pub type_name: String, pub nullable: bool, } #[derive(Debug, Clone)] pub enum Clause { Binding(Binding), Traversal(Traversal), Filter(Filter), Negation(Vec), } #[derive(Debug, Clone)] pub struct Binding { pub variable: String, pub type_name: String, pub prop_matches: Vec, } #[derive(Debug, Clone)] pub struct PropMatch { pub prop_name: String, pub value: MatchValue, } #[derive(Debug, Clone)] pub enum MatchValue { Literal(Literal), Variable(String), Now, } #[derive(Debug, Clone)] pub struct Traversal { pub src: String, pub edge_name: String, pub dst: String, pub min_hops: u32, pub max_hops: Option, /// `$a $b` — match the edge in either direction (set semantics; /// same-endpoint-type edges only, enforced at typecheck). pub undirected: bool, } #[derive(Debug, Clone)] pub struct Filter { pub left: Expr, pub op: CompOp, pub right: Expr, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum CompOp { Eq, Ne, Gt, Lt, Ge, Le, Contains, } impl std::fmt::Display for CompOp { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Eq => write!(f, "="), Self::Ne => write!(f, "!="), Self::Gt => write!(f, ">"), Self::Lt => write!(f, "<"), Self::Ge => write!(f, ">="), Self::Le => write!(f, "<="), Self::Contains => write!(f, "contains"), } } } #[derive(Debug, Clone)] pub enum Expr { Now, PropAccess { variable: String, property: String, }, Nearest { variable: String, property: String, query: Box, }, Search { field: Box, query: Box, }, Fuzzy { field: Box, query: Box, max_edits: Option>, }, MatchText { field: Box, query: Box, }, Bm25 { field: Box, query: Box, }, Rrf { primary: Box, secondary: Box, k: Option>, }, Variable(String), Literal(Literal), Aggregate { func: AggFunc, arg: Box, }, AliasRef(String), } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum AggFunc { Count, Sum, Avg, Min, Max, } impl std::fmt::Display for AggFunc { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Count => write!(f, "count"), Self::Sum => write!(f, "sum"), Self::Avg => write!(f, "avg"), Self::Min => write!(f, "min"), Self::Max => write!(f, "max"), } } } #[derive(Debug, Clone)] pub enum Literal { Null, String(String), Integer(i64), Float(f64), Bool(bool), Date(String), DateTime(String), List(Vec), } #[derive(Debug, Clone)] pub struct Projection { pub expr: Expr, pub alias: Option, } #[derive(Debug, Clone)] pub struct Ordering { pub expr: Expr, pub descending: bool, } #[derive(Debug, Clone)] pub enum Mutation { Insert(InsertMutation), Update(UpdateMutation), Delete(DeleteMutation), } #[derive(Debug, Clone)] pub struct InsertMutation { pub type_name: String, pub assignments: Vec, } #[derive(Debug, Clone)] pub struct UpdateMutation { pub type_name: String, pub assignments: Vec, pub predicate: MutationPredicate, } #[derive(Debug, Clone)] pub struct DeleteMutation { pub type_name: String, pub predicate: MutationPredicate, } #[derive(Debug, Clone)] pub struct MutationAssignment { pub property: String, pub value: MatchValue, } #[derive(Debug, Clone)] pub struct MutationPredicate { pub property: String, pub op: CompOp, pub value: MatchValue, }