16 releases (2 stable)

Uses old Rust 2015

1.1.0 Apr 25, 2017
1.0.0 Feb 3, 2017
1.0.0-rc2 Jan 27, 2017
0.9.1 Jul 11, 2016
0.7.1 Nov 7, 2015

#209 in Database interfaces

Download history 58/week @ 2021-02-24 54/week @ 2021-03-03 81/week @ 2021-03-10 36/week @ 2021-03-17 167/week @ 2021-03-24 137/week @ 2021-03-31 122/week @ 2021-04-07 118/week @ 2021-04-14 51/week @ 2021-04-21 67/week @ 2021-04-28 87/week @ 2021-05-05 74/week @ 2021-05-12 143/week @ 2021-05-19 55/week @ 2021-05-26 80/week @ 2021-06-02 44/week @ 2021-06-09

379 downloads per month
Used in 4 crates

MIT/Apache

50KB
909 lines

rusted_cypher

Rust crate for accessing the cypher endpoint of a neo4j server

This crate allows you to send cypher queries to the REST endpoint of a neo4j database. You can execute queries inside a transaction or simply send queries that commit immediately.

Examples

Connecting to a Neo4j database

use rusted_cypher::GraphClient;
let graph = GraphClient::connect(
    "http://neo4j:neo4j@localhost:7474/db/data");

Performing Queries

let mut query = graph.query();

// Statement implements From<&str>
query.add_statement(
    "CREATE (n:LANG { name: 'Rust', level: 'low', safe: true })");

let statement = Statement::new(
    "CREATE (n:LANG { name: 'C++', level: 'low', safe: {safeness} })")
    .with_param("safeness", false)?;

query.add_statement(statement);

query.send()?;

graph.exec(
    "CREATE (n:LANG { name: 'Python', level: 'high', safe: true })")?;

let result = graph.exec(
    "MATCH (n:LANG) RETURN n.name, n.level, n.safe")?;

assert_eq!(result.data.len(), 3);

for row in result.rows() {
    let name: String = row.get("n.name")?;
    let level: String = row.get("n.level")?;
    let safeness: bool = row.get("n.safe")?;
    println!("name: {}, level: {}, safe: {}", name, level, safeness);
}

graph.exec("MATCH (n:LANG) DELETE n")?;

With Transactions

let transaction = graph
    .transaction()
    .with_statement(
        "CREATE (n:IN_TRANSACTION { name: 'Rust', level: 'low', safe: true })");

let (mut transaction, results) = transaction.begin().unwrap();

// Use `exec` to execute a single statement
transaction.exec("CREATE (n:IN_TRANSACTION { name: 'Python', level: 'high', safe: true })")?;

// use `add_statement` (or `with_statement`) and `send` to executes multiple statements
let stmt = Statement::new(
    "MATCH (n:IN_TRANSACTION) WHERE (n.safe = {safeness}) RETURN n")
    .with_param("safeness", true)?;

transaction.add_statement(stmt);
let results = transaction.send()?;

assert_eq!(results[0].data.len(), 2);

transaction.rollback()?;
}

Statements with Macro

There is a macro to help building statements

let statement = cypher_stmt!(
    "CREATE (n:WITH_MACRO { name: {name}, level: {level}, safe: {safe} })", {
        "name" => "Rust",
        "level" => "low",
        "safe" => true
    }
)?;
graph.exec(statement)?;

let statement = cypher_stmt!(
    "MATCH (n:WITH_MACRO) WHERE n.name = {name} RETURN n", {
        "name" => "Rust"
    }
)?;

let results = graph.exec(statement)?;
assert_eq!(results.data.len(), 1);

let statement = cypher_stmt!("MATCH (n:WITH_MACRO) DELETE n")?;
graph.exec(statement)?;

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~8.5MB
~211K SLoC