在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
Run Code Online (Sandbox Code Playgroud)
处理复杂文件时,可以对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'}))
Run Code Online (Sandbox Code Playgroud)
这意味着我可以单独运行cypher语句,但性能受到重创.我可以为节点和关系编写CREATE/MERGE但是我希望不必重新编写我已经使用的一堆例程.我错过了什么?
在py2neo v3中,您仍然可以使用事务,但API已经发生了一些变化.
在示例代码中,您现在必须:
graph.begin而不是 graph.cypher.begin.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()
Run Code Online (Sandbox Code Playgroud)