rusted_cypher 0.6.0

Send cypher queries to a neo4j database
docs.rs failed to build rusted_cypher-0.6.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: rusted_cypher-1.1.0

rusted_cypher

Rust crate for accessing the cypher endpoint of a neo4j server

This is a prototype for accessing the cypher endpoint of a neo4j server, like a sql driver for a relational database.

You can execute queries inside a transaction or simply execute queries that commit immediately.

Examples

Code in examples are assumed to be wrapped in:

extern crate rusted_cypher;

use std::collections::BTreeMap;
use rusted_cypher::GraphClient;
use rusted_cypher::cypher::Statement;

fn main() {
  // Connect to the database
  let graph = GraphClient::connect(
      "http://neo4j:neo4j@localhost:7474/db/data").unwrap();

  // Example code here!
}

Performing Queries

let mut query = graph.cypher().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().unwrap();

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

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

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

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

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

With Transactions

let transaction = graph.cypher().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 })")
    .unwrap();

// 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().unwrap();

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

transaction.rollback();

License: MIT