Skip to main content

sqlitegraph_cli/
query.rs

1//! CLI query module — delegates to core cypher module.
2//!
3//! This module provides the CLI-specific interface for parsing and executing
4//! Cypher-inspired queries. The actual parser and executor live in
5//! `sqlitegraph::cypher`.
6
7use serde_json::Value;
8use sqlitegraph::backend::SqliteGraphBackend;
9
10/// Parse and execute a Cypher-inspired query string.
11///
12/// Delegates to `sqlitegraph::cypher::parse` and `sqlitegraph::cypher::execute`.
13/// Returns a JSON value with `{"results": [...], "count": N}`.
14pub fn run(backend: &SqliteGraphBackend, query_str: &str) -> anyhow::Result<Value> {
15    let query =
16        sqlitegraph::cypher::parse(query_str).map_err(|e| anyhow::anyhow!("parse error: {e}"))?;
17    let result = sqlitegraph::cypher::execute(backend, &query)
18        .map_err(|e| anyhow::anyhow!("execution error: {e}"))?;
19    Ok(result)
20}