use kglite::api::{load_file, session, Value};
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = std::env::args()
.nth(1)
.ok_or("Usage: embedded_basic <path/to/graph.kgl>")?;
let graph = load_file(&path)?;
println!(
"Loaded {}: {} bytes resident",
path,
std::mem::size_of_val(&*graph)
);
let params = HashMap::new();
let opts = session::ExecuteOptions {
params: ¶ms,
deadline: None,
max_rows: None,
lazy_eligible: false,
disabled_passes: None,
embedder: None,
};
let outcome = session::execute_read(&graph, "MATCH (n) RETURN count(n) AS total", &opts)?;
for row in &outcome.result.rows {
if let Some(Value::Int64(n)) = row.first() {
println!("Total nodes: {}", n);
}
}
let outcome =
session::execute_read(&graph, "MATCH (n) RETURN n.title AS title LIMIT 5", &opts)?;
println!("\nSample nodes:");
for row in &outcome.result.rows {
if let Some(Value::String(s)) = row.first() {
println!(" - {}", s);
}
}
Ok(())
}