#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ExplainType {
PhysicalPlan,
LogicalPlan,
Profile,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExportDatabase {
pub file_path: String,
pub options: std::collections::HashMap<String, String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ImportDatabase {
pub file_path: String,
pub options: std::collections::HashMap<String, String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct AnalyzeStatement {
pub table_name: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TransactionAction {
Begin,
Commit,
Rollback,
Checkpoint,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TransactionStatement {
pub action: TransactionAction,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ExtensionAction {
Install,
Load,
Uninstall,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExtensionStatement {
pub action: ExtensionAction,
pub name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct AttachDatabase {
pub path: String,
pub alias: String,
pub options: std::collections::HashMap<String, String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DetachDatabase {
pub alias: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct UseDatabase {
pub alias: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LoadFrom {
pub path: String,
pub options: std::collections::HashMap<String, String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExplainStatement {
pub statement: Box<Statement>,
pub explain_type: ExplainType,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Statement {
Query(Query),
CreateNodeTable(CreateNodeTable),
CreateRelTable(CreateRelTable),
DropTable(DropTable),
CopyFrom(CopyFrom),
CopyTo(CopyTo),
AlterTable(AlterTable),
CreateVectorIndex(CreateVectorIndex),
CreateIndex(CreateIndex),
DropIndex(DropIndex),
Union(UnionStatement),
Merge(MergeStatement),
StandaloneCall(StandaloneCall),
CreateDml(CreateClause),
Explain(ExplainStatement),
CreateSequence(CreateSequence),
DropSequence(DropSequence),
CreateMacro(CreateMacro),
ExportDatabase(ExportDatabase),
ImportDatabase(ImportDatabase),
Analyze(AnalyzeStatement),
CreateFtsIndex(CreateFtsIndex),
Transaction(TransactionStatement),
Extension(ExtensionStatement),
AttachDatabase(AttachDatabase),
DetachDatabase(DetachDatabase),
UseDatabase(UseDatabase),
LoadFrom(LoadFrom),
CreateType(CreateType),
CommentOnTable(CommentOnTable),
CreateGraph(CreateGraph),
UseGraph(UseGraph),
DropGraph(DropGraph),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Query {
pub clauses: Vec<Clause>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Clause {
Match(MatchClause),
Return(ReturnClause),
Where(WhereClause),
Create(CreateClause),
Delete(DeleteClause),
Set(SetClause),
OptionalMatch(OptionalMatchClause),
With(ReturnClause),
Unwind(UnwindClause),
Foreach(ForeachClause),
Merge(MergeStatement),
}
#[derive(Debug, Clone, PartialEq)]
pub struct ForeachClause {
pub variable: String,
pub expression: Expression,
pub clauses: Vec<Clause>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct UnwindClause {
pub expression: Expression,
pub variable: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SetClause {
pub items: Vec<SetItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SetItem {
pub property: Expression,
pub value: Expression,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DeleteClause {
pub detach: bool,
pub expressions: Vec<Expression>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct MatchClause {
pub patterns: Vec<Pattern>,
pub fts_query: Option<FtsQuery>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FtsQuery {
pub index_name: String,
pub query_string: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateFtsIndex {
pub index_name: String,
pub table_name: String,
pub column_name: String,
pub if_not_exists: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct OptionalMatchClause {
pub patterns: Vec<Pattern>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ReturnClause {
pub expressions: Vec<ReturnItem>,
pub distinct: bool,
pub order_by: Option<Vec<OrderByItem>>,
pub limit: Option<u64>,
pub skip: Option<u64>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ReturnItem {
pub expression: Expression,
pub alias: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct OrderByItem {
pub expression: Expression,
pub ascending: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WhereClause {
pub expression: Expression,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateClause {
pub patterns: Vec<Pattern>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Pattern {
pub node: Option<NodePattern>,
pub edge: Option<EdgePattern>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct NodePattern {
pub variable: Option<String>,
pub labels: Vec<String>,
pub properties: Vec<(String, Expression)>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct EdgePattern {
pub variable: Option<String>,
pub labels: Vec<String>,
pub direction: EdgeDirection,
pub properties: Vec<(String, Expression)>,
pub lower_bound: Option<u64>,
pub upper_bound: Option<u64>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum EdgeDirection {
LeftToRight,
RightToLeft,
Both,
}
impl ExplainStatement {
pub fn new(statement: Statement, explain_type: ExplainType) -> Self {
Self {
statement: Box::new(statement),
explain_type,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum Expression {
Constant(Constant),
Variable(String),
Parameter(String),
PropertyAccess(Box<Expression>, String),
FunctionCall(String, Vec<Expression>),
BinaryOp(BinaryOp, Box<Expression>, Box<Expression>),
UnaryOp(UnaryOp, Box<Expression>),
List(Vec<Expression>),
Map(Vec<(String, Expression)>),
ExistsSubquery(Box<Query>),
Case(CaseExpr),
Star,
ListPredicate {
quantifier: Quantifier,
list: Box<Expression>,
var_name: String,
predicate: Box<Expression>,
},
Lambda {
var_name: String,
body: Box<Expression>,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Quantifier {
Any,
All,
None,
Single,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CaseAlternative {
pub when: Expression,
pub then: Expression,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CaseExpr {
pub subject: Option<Box<Expression>>,
pub alternatives: Vec<CaseAlternative>,
pub else_expr: Option<Box<Expression>>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Constant {
Null,
Bool(bool),
Integer(i64),
Float(f64),
String(String),
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum BinaryOp {
Add,
Subtract,
Multiply,
Divide,
Modulo,
Equal,
NotEqual,
LessThan,
LessThanOrEqual,
GreaterThan,
GreaterThanOrEqual,
And,
Or,
Xor,
Concat,
In,
NotIn,
StartsWith,
EndsWith,
Contains,
Like,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum UnaryOp {
Not,
Negate,
IsNull,
IsNotNull,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateNodeTable {
pub name: String,
pub columns: Vec<ColumnDef>,
pub primary_key: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateRelTable {
pub name: String,
pub from: String,
pub to: String,
pub columns: Vec<ColumnDef>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DropTable {
pub name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateIndex {
pub index_type: String,
pub index_name: String,
pub table_name: String,
pub variable: String,
pub property: String,
pub conflict_action: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DropIndex {
pub index_name: String,
pub table_name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct AlterTable {
pub table_name: String,
pub action: AlterAction,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AlterAction {
AddColumn { name: String, type_name: String },
DropColumn { name: String },
RenameColumn { old_name: String, new_name: String },
RenameTable { new_name: String },
}
#[derive(Debug, Clone, PartialEq)]
pub struct UnionStatement {
pub left: Query,
pub right: Query,
pub all: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CopyFrom {
pub table_name: String,
pub file_path: String,
pub options: std::collections::HashMap<String, String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CopyTo {
pub query: Query,
pub file_path: String,
pub format: CopyToFormat,
pub header: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum CopyToFormat {
Csv,
Parquet,
}
#[derive(Debug, Clone, PartialEq)]
pub struct MergeStatement {
pub patterns: Vec<Pattern>,
pub on_create: Vec<SetItem>,
pub on_match: Vec<SetItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StandaloneCall {
pub function_name: String,
pub args: Vec<Expression>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateSequence {
pub name: String,
pub if_not_exists: bool,
pub or_replace: bool,
pub start_with: Option<i64>,
pub increment: Option<i64>,
pub min_value: Option<i64>,
pub max_value: Option<i64>,
pub cycle: Option<bool>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DropSequence {
pub name: String,
pub if_exists: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateMacro {
pub name: String,
pub positional_args: Vec<String>,
pub default_args: Vec<(String, Expression)>,
pub expression: Box<Expression>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateVectorIndex {
pub index_name: String,
pub table_name: String,
pub column_name: String,
pub metric: String,
pub dimensions: u64,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ColumnDef {
pub name: String,
pub type_name: String,
pub compression: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateType {
pub name: String,
pub type_name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CommentOnTable {
pub table_name: String,
pub comment: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateGraph {
pub name: String,
pub is_any: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct UseGraph {
pub name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DropGraph {
pub name: String,
}