16 个版本 (2 个稳定版)

使用旧的 Rust 2015

1.1.0 2017 年 4 月 25 日
1.0.0 2017 年 2 月 3 日
1.0.0-rc22017 年 1 月 27 日
0.9.1 2016 年 7 月 11 日
0.7.1 2015 年 11 月 7 日

#1943数据库接口

Download history 44/week @ 2024-03-04 74/week @ 2024-03-11 61/week @ 2024-03-18 60/week @ 2024-03-25 81/week @ 2024-04-01 74/week @ 2024-04-08 83/week @ 2024-04-15 57/week @ 2024-04-22 36/week @ 2024-04-29 41/week @ 2024-05-06 39/week @ 2024-05-13 46/week @ 2024-05-20 62/week @ 2024-05-27 37/week @ 2024-06-03 40/week @ 2024-06-10 48/week @ 2024-06-17

189 每月下载
用于 4 crates

MIT/Apache

50KB
909

rusted_cypher

Rust crate 用于访问 Neo4j 服务器的 Cypher 端点

此 crate 允许您向 Neo4j 数据库的 REST 端点发送 Cypher 查询。您可以在事务中执行查询或简单地发送立即提交的查询。

示例

连接到 Neo4j 数据库

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

执行查询

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")?;

使用事务

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()?;
}

使用宏的语句

有一个宏来帮助构建语句

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)?;

许可证

根据您选择的以下任一项许可

贡献

除非您明确说明,否则您有意提交的任何贡献,根据 Apache-2.0 许可证定义,将根据上述条款双许可,不附加任何额外条款或条件。

依赖关系

~9.5MB
~216K SLoC