Skip to content

Commit

Permalink
add rust code sample
Browse files Browse the repository at this point in the history
  • Loading branch information
barakb committed Dec 11, 2024
1 parent beec6e1 commit 7f171d5
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,66 @@ public class FalkorDBExample {
}
{% endcapture %}

{% include code_tabs.html id="code_tabs_0" python=python_code javascript=javascript_code java=java_code %}
{% capture rust_code %}
use falkordb::{FalkorClientBuilder, FalkorConnectionInfo};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to FalkorDB
let connection_info: FalkorConnectionInfo = "falkor://127.0.0.1:6379"
.try_into()
.expect("Invalid connection info");

let client = FalkorClientBuilder::new_async()
.with_connection_info(connection_info)
.build()
.await?;

// Select the 'MotoGP' graph
let mut graph = client.select_graph("MotoGP");

// Clear out this graph in case you've run this script before.
graph.delete().await?;

graph
.query(
r#"CREATE
(:Rider {name:'Valentino Rossi'})-[:rides]->(:Team {name:'Yamaha'}),
(:Rider {name:'Dani Pedrosa'})-[:rides]->(:Team {name:'Honda'}),
(:Rider {name:'Andrea Dovizioso'})-[:rides]->(:Team {name:'Ducati'})"#,
)
.execute()
.await?;

// Query which riders represent Yamaha?
let mut nodes = graph
.query(
r#"MATCH (r:Rider)-[:rides]->(t:Team)
WHERE t.name = 'Yamaha'
RETURN r.name"#,
)
.execute()
.await?;

for node in nodes.data.by_ref() {
println!("{:?}", node);
}

// Query how many riders represent team Ducati?
let mut nodes = graph
.query(r#"MATCH (r:Rider)-[:rides]->(t:Team {name:'Ducati'}) RETURN count(r)"#)
.execute()
.await?;

for node in nodes.data.by_ref() {
println!("{:?}", node);
}

Ok(())
}
{% endcapture %}

{% include code_tabs.html id="code_tabs_0" python=python_code javascript=javascript_code java=java_code rust=rust_code %}

For additional demos please see visit [Demos](https://github.com/FalkorDB/demos).

Expand Down

0 comments on commit 7f171d5

Please sign in to comment.