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::GraphBackend;
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}`.
14///
15/// This function is generic over the GraphBackend trait, allowing it to work
16/// with both SQLite and native-v3 backends.
17pub fn run<B: GraphBackend>(backend: &B, query_str: &str) -> anyhow::Result<Value> {
18    let query =
19        sqlitegraph::cypher::parse(query_str).map_err(|e| anyhow::anyhow!("parse error: {e}"))?;
20    let result = sqlitegraph::cypher::execute(backend, &query)
21        .map_err(|e| anyhow::anyhow!("execution error: {e}"))?;
22    Ok(result)
23}