1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
//! 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. //! //! # Serialization: `serde` vs `rustc-serialize` //! //! By default, `rusted-cypher` supports types that implement [serde](https://github.com/serde-rs/serde) //! traits, `Serialize` and `Deserialize`, in query parameters and to retrieve result values. //! If you want to use `rustc-serialize` instead, just add the feature `rustc-serialize`: //! //! ```toml //! [dependencies] //! rusted_cypher = { version = "*", features = ["rustc-serialize"] } //! ``` //! //! # 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 //! //! ``` //! # use rusted_cypher::GraphClient; //! # use rusted_cypher::cypher::Statement; //! # let graph = GraphClient::connect("http://neo4j:neo4j@localhost:7474/db/data").unwrap(); //! 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 //! //! ``` //! # use std::collections::BTreeMap; //! # use rusted_cypher::GraphClient; //! # use rusted_cypher::cypher::Statement; //! # let graph = GraphClient::connect("http://neo4j:neo4j@localhost:7474/db/data").unwrap(); //! 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(); //! ``` //! //! ## Statements with Macro //! //! There is a macro to help building statements //! //! ``` //! # #[macro_use] extern crate rusted_cypher; //! # use rusted_cypher::GraphClient; //! # use rusted_cypher::cypher::Statement; //! # fn main() { //! # let graph = GraphClient::connect("http://neo4j:neo4j@localhost:7474/db/data").unwrap(); //! let statement = cypher_stmt!( //! "CREATE (n:WITH_MACRO { name: {name}, level: {level}, safe: {safe} })", { //! "name" => "Rust", //! "level" => "low", //! "safe" => true //! } //! ); //! graph.cypher().exec(statement).unwrap(); //! //! let statement = cypher_stmt!("MATCH (n:WITH_MACRO) WHERE n.name = {name} RETURN n", { //! "name" => "Rust" //! }); //! //! let results = graph.cypher().exec(statement).unwrap(); //! assert_eq!(results.data.len(), 1); //! //! let statement = cypher_stmt!("MATCH (n:WITH_MACRO) DELETE n"); //! graph.cypher().exec(statement).unwrap(); //! # } //! ``` #![cfg_attr(feature = "serde_macros", feature(custom_attribute, custom_derive, plugin))] #![cfg_attr(feature = "serde_macros", plugin(serde_macros))] pub extern crate hyper; pub extern crate url; pub extern crate serde; pub extern crate serde_json; #[cfg(feature = "rustc-serialize")] pub extern crate rustc_serialize; extern crate semver; pub extern crate time; #[macro_use] extern crate quick_error; #[macro_use] pub extern crate log; #[cfg(feature = "serde_macros")] include!("lib.rs.in"); #[cfg(not(feature = "serde_macros"))] include!(concat!(env!("OUT_DIR"), "/lib.rs"));