在 py2neo v2.0 中,可以使用事务来执行 Cypher 语句:
tx=graph.cypher.begin()
tx.append("MERGE (n:Process {proc_nm : {proc_nm}}) ON CREATE SET n.count = 1 ON MATCH SET n.count = n.count +1", {proc_nm : 'wibble'})
tx.commit
当处理复杂文件时,这允许对 Neo4J 数据库进行非常快速的更新。
在 py2neo v3.0 中,语法已更改为:
graph.run(("MERGE (n:Process {proc_nm : {proc_nm}}) ON CREATE SET n.count = 1 ON MATCH SET n.count = n.count +1", {proc_nm : 'wibble'}))
这意味着我可以单独运行密码语句,但性能会受到巨大影响。我可以为节点和关系编写 CREATE/MERGE,但是我希望不必重写一堆我已经在使用的例程。我缺少什么?
在 py2neo v3 中,您仍然可以使用交易 http://py2neo.org/v3/database.html#py2neo.database.Transaction,但 API 发生了一些变化。
在示例代码中,您现在必须:
- Use
graph.begin
代替graph.cypher.begin
.
- Use
tx.run
代替tx.append
.
此模式应该适用于 v3:
tx=graph.begin()
tx.run(" ... Cypher statement 1 ... ", { ... })
tx.run(" ... Cypher statement 2 ... ", { ... })
tx.run(" ... Cypher statement 3 ... ", { ... })
tx.commit()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)