use falkordb::{FalkorClientBuilder, FalkorConnectionInfo};
use std::collections::BTreeMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let connection_info: FalkorConnectionInfo = "falkor://127.0.0.1:6379".try_into()?;
let client = FalkorClientBuilder::new()
.with_connection_info(connection_info)
.build()?;
let mut graph = client.select_graph("typed_params_example");
let _ = graph.delete();
graph
.query("CREATE (:Movie {title: $title, year: $year, rating: $rating})")
.with_param("title", "The Matrix")
.with_param("year", 1999)
.with_param("rating", 8.7)
.execute()?;
graph
.query("CREATE (:Movie {title: $title, year: $year})")
.with_param("title", "'; MATCH (n) DETACH DELETE n //")
.with_param("year", 2003)
.execute()?;
let mut titles = graph
.query("MATCH (m:Movie) WHERE m.year IN $years RETURN m.title AS title ORDER BY m.year")
.with_param("years", [1999, 2003])
.execute()?;
for row in titles.data.by_ref() {
let title: String = row?.try_get("title")?;
println!("matched: {title}");
}
let coords = BTreeMap::from([("latitude", 32.07), ("longitude", 34.79)]);
let mut located = graph
.query("RETURN point($p)")
.with_param("p", coords)
.execute()?;
if let Some(row) = located.data.next() {
println!("point: {:?}", row?.get_at(0));
}
graph.delete()?;
Ok(())
}