Skip to content

Commit

Permalink
Merge pull request #103 from FalkorDB/add_rust_example
Browse files Browse the repository at this point in the history
add rust code sample
  • Loading branch information
barakb authored Dec 11, 2024
2 parents beec6e1 + 14325b4 commit ba2d879
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,15 @@ userName
www
yourQuery
yourSourceName
htmlcontent
index.md
html
body
p
FalkorClientBuilder
FalkorConnectionInfo
h1
tokio
async
falkor
fn
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 ba2d879

Please sign in to comment.