本文介绍了如何在Py2neo v3中将密码查询合并到事务中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在py2neo v2.0中,可以使用事务执行Cypher语句:

In py2neo v2.0, it was possible to use a transaction to execute Cypher statements:

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数据库进行非常快速的更新.

When processing complex files this allows very fast updates to be made to the Neo4J database.

在py2neo v3.0中,语法已更改为:

In py2neo v3.0 the syntax has changed to:

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'}))

这意味着我可以单独运行cypher语句,但是性能受到很大的打击.我可以为节点和关系编写CREATE/MERGE,但是我希望不必重新编写一堆已经在使用的例程.我想念什么?

This means that I can run the cypher statements singly but the performance takes a massive hit. I can write CREATE/MERGE for the Nodes and Relationships however I was hoping to not have to re-write a bunch of routines that I'm already using. What am I missing?

推荐答案

在py2neo v3中,您仍然可以使用交易,但API有所更改.

In py2neo v3, you can still use a Transaction, but the API has changed a bit.

在示例代码中,您现在必须:

In your sample code, you must now:

  • 使用graph.begin代替graph.cypher.begin.
  • 使用tx.run代替tx.append.
  • Use graph.begin instead of graph.cypher.begin.
  • Use tx.run instead of tx.append.

此模式应在v3中运行:

This pattern should work in v3:

tx=graph.begin()
tx.run(" ... Cypher statement 1 ... ", { ... })
tx.run(" ... Cypher statement 2 ... ", { ... })
tx.run(" ... Cypher statement 3 ... ", { ... })
tx.commit()

这篇关于如何在Py2neo v3中将密码查询合并到事务中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:34