use relate_names::SmallName;
mod clause;
pub use clause::*;
mod expr;
pub use expr::*;
mod graph_type;
pub use graph_type::*;
mod pattern;
pub use pattern::*;
mod schema;
pub use schema::*;
mod search;
pub use search::*;
mod show;
pub use show::*;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum PreambleMode {
#[default]
Execute,
Explain,
Profile,
}
#[derive(Debug, Clone, Default)]
pub struct Statement {
pub clauses: Vec<Clause>,
pub union: Option<Box<UnionPart>>,
pub preamble: PreambleMode,
pub next: Option<Box<Statement>>,
pub brace_wrapped: bool,
pub definitions: Vec<LocalDefinition>,
}
impl Statement {
pub fn tail_stage(&self) -> &Statement {
let mut stage = self;
while let Some(next) = &stage.next {
stage = next;
}
stage
}
pub fn projection_stage(&self) -> &Statement {
if self.union.is_some() {
self
} else {
self.tail_stage()
}
}
pub fn projects_columns(&self) -> bool {
match self.projection_stage().clauses.last() {
Some(Clause::Return(_)) => true,
Some(Clause::Conditional(cc)) => {
cc.branches
.first()
.expect("a WHEN clause has at least one branch")
.body
.projects_columns()
}
Some(Clause::CallSubquery(inner)) => inner.statement.projects_columns(),
_ => false,
}
}
}
impl PartialEq for Statement {
fn eq(&self, other: &Self) -> bool {
self.clauses == other.clauses
&& self.union == other.union
&& self.preamble == other.preamble
&& self.next == other.next
&& self.definitions == other.definitions
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct LocalDefinition {
pub kind: LocalCallableKind,
pub name: SmallName,
pub params: Vec<LocalParam>,
pub output: Option<LocalOutput>,
pub body: LocalDefinitionBody,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LocalCallableKind {
Procedure,
Function,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LocalParam {
pub name: SmallName,
pub type_expr: Option<TypeExpr>,
pub default: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum LocalOutput {
Fields(Vec<LocalOutputField>),
Type(TypeExpr),
}
#[derive(Debug, Clone, PartialEq)]
pub struct LocalOutputField {
pub name: SmallName,
pub type_expr: Option<TypeExpr>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum LocalDefinitionBody {
Expression(Expr),
Query(Statement),
}
#[derive(Debug, Clone, PartialEq)]
pub struct UnionPart {
pub all: bool,
pub statement: Statement,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Clause {
Match(MatchClause),
Create(CreateClause),
Merge(MergeClause),
Delete(DeleteClause),
Set(SetClause),
Remove(RemoveClause),
Return(ReturnClause),
With(WithClause),
Unwind(UnwindClause),
CreateIndex(CreateIndexClause),
DropIndex(DropIndexClause),
CreateConstraint(CreateConstraintClause),
DropConstraint(DropConstraintClause),
Foreach(ForeachClause),
LoadCSV(LoadCSVClause),
CallSubquery(CallSubqueryClause),
CallProcedure(CallProcedureClause),
ShowFunctions(ShowFunctionsClause),
ShowConstraints(ShowConstraintsClause),
ShowIndexes(ShowIndexesClause),
ShowDatabases(ShowDatabasesClause),
ShowRoles(ShowRolesClause),
ShowServers(ShowServersClause),
ShowUsers(ShowUsersClause),
ShowProcedures(ShowProceduresClause),
ShowSettings(ShowSettingsClause),
ShowTransactions(ShowTransactionsClause),
TerminateTransactions(TerminateTransactionsClause),
Use(UseClause),
Finish,
StandaloneOrderBy(StandaloneOrderByClause),
Conditional(ConditionalClause),
AlterCurrentGraphType(AlterCurrentGraphTypeClause),
CreateGraphType(CreateGraphTypeClause),
ShowGraphType(ShowGraphTypeClause),
ShowCurrentGraphType(ShowCurrentGraphTypeClause),
AlterDatabase(AlterDatabaseClause),
}
impl Clause {
pub fn keyword(&self) -> &'static str {
match self {
Clause::Match(_) => "MATCH",
Clause::Create(_) => "CREATE",
Clause::Merge(_) => "MERGE",
Clause::Delete(_) => "DELETE",
Clause::Set(_) => "SET",
Clause::Remove(_) => "REMOVE",
Clause::Return(_) => "RETURN",
Clause::With(_) => "WITH",
Clause::Unwind(_) => "UNWIND",
Clause::CreateIndex(_) => "CREATE INDEX",
Clause::DropIndex(_) => "DROP INDEX",
Clause::CreateConstraint(_) => "CREATE CONSTRAINT",
Clause::DropConstraint(_) => "DROP CONSTRAINT",
Clause::Foreach(_) => "FOREACH",
Clause::LoadCSV(_) => "LOAD CSV",
Clause::CallSubquery(_) | Clause::CallProcedure(_) => "CALL",
Clause::ShowFunctions(_) => "SHOW FUNCTIONS",
Clause::ShowConstraints(_) => "SHOW CONSTRAINTS",
Clause::ShowIndexes(_) => "SHOW INDEXES",
Clause::ShowDatabases(_) => "SHOW DATABASES",
Clause::ShowRoles(_) => "SHOW ROLES",
Clause::ShowServers(_) => "SHOW SERVERS",
Clause::ShowUsers(_) => "SHOW USERS",
Clause::ShowProcedures(_) => "SHOW PROCEDURES",
Clause::ShowSettings(_) => "SHOW SETTINGS",
Clause::ShowTransactions(_) => "SHOW TRANSACTIONS",
Clause::TerminateTransactions(_) => "TERMINATE TRANSACTIONS",
Clause::Use(_) => "USE",
Clause::Finish => "FINISH",
Clause::StandaloneOrderBy(_) => "ORDER BY",
Clause::Conditional(_) => "WHEN",
Clause::AlterCurrentGraphType(_) => "ALTER CURRENT GRAPH TYPE",
Clause::CreateGraphType(_) => "CREATE GRAPH TYPE",
Clause::ShowGraphType(_) => "SHOW GRAPH TYPE",
Clause::ShowCurrentGraphType(_) => "SHOW CURRENT GRAPH TYPE",
Clause::AlterDatabase(_) => "ALTER DATABASE",
}
}
}
mod expr_children;
pub use expr_children::{ExprEdge, ExprEdgeMut};