Neo4rs is a native rust driver implemented using bolt 4.1 specification
Run a simple query, discard the response data
rust
let uri = "127.0.0.1:7687".to_owned();
let user = "neo4j";
let pass = "neo4j";
let graph = Graph::connect(uri, user, pass).await.unwrap();
assert!(graph.query("RETURN 1").run().await.is_ok());
Create a node and process the response
rust
let graph = Graph::connect(uri, user, pass).await.unwrap();
let mut result = graph
.query("CREATE (friend:Person {name: $name}) RETURN friend")
.param("name", "Mark")
.execute()
.await
.unwrap();
let row = result.next().await.unwrap();
let node: Node = row.get("friend").unwrap();
let id = node.id();
let labels = node.labels();
let name: String = node.get("name").unwrap();
assert_eq!(name, "Mark");
assert_eq!(labels, vec!["Person"]);
Drain the result stream
```rust
let graph = Graph::connect(uri, user, pass).await.unwrap();
let mut result = graph
.query("MATCH (p:Person {name: 'Mark'}) RETURN p")
.execute()
.await
.unwrap();
while let Some(row) = result.next().await {
let node: Node = row.get("friend").unwrap();
let name: String = node.get("name").unwrap();
//process name & node
}
```
Create explicit transactions
```rust let graph = Graph::connect(uri, user, pass).await.unwrap(); let txn = graph.begintxn().await.unwrap(); graph.query("CREATE (p:Person {id: 'someid'})").run().await.unwrap(); txn.commit().await.unwrap();
//Rollback a transaction
//txn.rollback().await.unwrap();
```
Create and parse relationship
```rust let graph = Graph::connect(uri, user, pass).await.unwrap(); let mut result = graph .query("CREATE (p:Person { name: 'Mark' })-[r:WORKS_AT {as: 'Engineer'}]->(neo) RETURN r") .execute() .await .unwrap();
let row = result.next().await.unwrap();
let relation: Relation = row.get("r").unwrap();
assert!(relation.id() > 0);
assert!(relation.start_node_id() > 0);
assert!(relation.end_node_id() > 0);
assert_eq!(relation.typ(), "WORKS_AT");
assert_eq!(relation.get::<String>("as").unwrap(), "Engineer");
```
neo4rs is available on crates.io and can be included in your Cargo enabled project like this:
toml
[dependencies]
neo4rs = "0.1.1"