1#![recursion_limit = "256"]
24
25pub mod procedures_plugin;
26pub mod projection_store;
27pub mod query;
28pub mod types;
29
30pub use query::executor::core::{OperatorStats, ProfileOutput};
31pub use query::executor::procedure::{
32 ProcedureOutput, ProcedureParam, ProcedureRegistry, ProcedureValueType, RegisteredProcedure,
33};
34pub use query::executor::{CustomFunctionRegistry, CustomScalarFn, Executor, ResultNormalizer};
35pub use query::df_udfs_plugin::{
40 CURRENT_PRINCIPAL, SESSION_PLUGIN_REGISTRY, current_principal, current_session_plugin_registry,
41 maybe_scope_with_principal, scoped_with_principal, scoped_with_session_context,
42 scoped_with_session_plugin_registry,
43};
44pub use query::planner::{
45 CostEstimates, ExplainOutput, ForkIndexLookup, FusionKind, IndexUsage, LogicalPlan,
46 QueryPlanner, rewrite_for_fork_fusion,
47};
48pub use types::{
49 Edge, ExecuteResult, FromValue, Node, Path, QueryCursor, QueryMetrics, QueryResult,
50 QueryWarning, Row, Value,
51};
52pub use uni_cypher::ast::{Query as CypherQuery, TimeTravelSpec};
53
54pub fn validate_read_only(query: &CypherQuery) -> Result<(), String> {
65 use uni_cypher::ast::{Clause, Query, Statement};
66
67 fn check_statement(stmt: &Statement) -> Result<(), String> {
68 for clause in &stmt.clauses {
69 match clause {
70 Clause::Create(_)
71 | Clause::Merge(_)
72 | Clause::Delete(_)
73 | Clause::Set(_)
74 | Clause::Remove(_) => {
75 return Err(
76 "Write clauses (CREATE, MERGE, DELETE, SET, REMOVE) are not allowed \
77 with VERSION AS OF / TIMESTAMP AS OF"
78 .to_string(),
79 );
80 }
81 _ => {}
82 }
83 }
84 Ok(())
85 }
86
87 fn check_query(q: &Query) -> Result<(), String> {
88 match q {
89 Query::Single(stmt) => check_statement(stmt),
90 Query::Union { left, right, .. } => {
91 check_query(left)?;
92 check_query(right)
93 }
94 Query::Explain(inner) => check_query(inner),
95 Query::TimeTravel { query, .. } => check_query(query),
96 Query::Schema(cmd) => {
97 use uni_cypher::ast::SchemaCommand;
98 match cmd.as_ref() {
99 SchemaCommand::ShowConstraints(_)
101 | SchemaCommand::ShowIndexes(_)
102 | SchemaCommand::ShowDatabase
103 | SchemaCommand::ShowConfig
104 | SchemaCommand::ShowStatistics => Ok(()),
105 _ => Err(
107 "Mutating schema commands are not allowed in read-only context".to_string(),
108 ),
109 }
110 }
111 }
112 }
113
114 check_query(query)
115}