Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clickgraph-embedded/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ impl<'db> Connection<'db> {
// in any arm enters the write pipeline, which executes it or refuses
// it clearly (a write in a UNION: "an updating clause in a UNION");
// the read path would answer "ClickGraph is read-only".
if prepared.targets.is_write() {
if clickgraph::bound_plan::write::is_write_statement(text) {
return self.handle_write_async(text).await;
}
self.query_with_executor_async(text, &self.executor).await
Expand Down
25 changes: 25 additions & 0 deletions src/bound_plan/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@ struct ReturnPlan {
guarded: Vec<Guard>,
}

/// Whether `cypher` (a statement without its prelude) has an updating clause
/// (CREATE / SET / REMOVE / DELETE) in any of its UNION arms. Reads only the
/// clause-list parser; a statement it does not read is not a write. Used by
/// the embedded dispatcher so a write in a later UNION arm (or one carrying a
/// COUNT { } the legacy parser cannot read) reaches the write path.
pub fn is_write_statement(cypher: &str) -> bool {
let Ok((_, stmt)) = crate::open_cypher_parser::clause_list::parse_clause_statement(cypher)
else {
return false;
};
let arms: Vec<&crate::open_cypher_parser::clause_list::ClauseQuery<'_>> =
std::iter::once(&stmt.first)
.chain(stmt.unions.iter().map(|(_, q)| q))
.collect();
arms.iter().flat_map(|q| &q.clauses).any(|c| {
matches!(
c,
crate::open_cypher_parser::clause_list::Clause::Create(_)
| crate::open_cypher_parser::clause_list::Clause::Set(_)
| crate::open_cypher_parser::clause_list::Clause::Remove(_)
| crate::open_cypher_parser::clause_list::Clause::Delete(_)
)
})
}

/// Plan the write statement `cypher` (comments stripped).
pub fn plan_write(cypher: &str, schema: &GraphSchema) -> Result<WritePlan, WritePlanError> {
let (rest, stmt) = crate::open_cypher_parser::clause_list::parse_clause_statement(cypher)
Expand Down
Loading