Python 使用py2neo事务更改节点属性
我正在尝试将py2neo作为事务的一部分来更新节点 问题是我似乎找不到与Python 使用py2neo事务更改节点属性,python,performance,neo4j,transactions,py2neo,Python,Performance,Neo4j,Transactions,Py2neo,我正在尝试将py2neo作为事务的一部分来更新节点 问题是我似乎找不到与Graph.push()类似的Transaction.push()。我错过了什么明显的东西吗 我的代码现在看起来是这样的,我想解析明显的??位 def write_to_database( self, t: Transaction ) -> None: n = None use_existing = False # Not part of the transaction: n = t
Graph.push()
类似的Transaction.push()
。我错过了什么明显的东西吗
我的代码现在看起来是这样的,我想解析明显的??位
def write_to_database( self, t: Transaction ) -> None:
n = None
use_existing = False
# Not part of the transaction:
n = t.graph.find_one( "Node", "name", self.name( ) )
if n:
use_existing = True
else:
n = Node(label)
n[ "name" ] = self.name( )
n["size"] = self.get_size()
if use_existing:
t.??????????????? # Put this in the transaction!
else:
t.create( n )
作为一个用例点,我之所以使用事务,是因为它似乎在1000秒的操作中运行得更快,而不是因为我需要回滚功能。您的整个方法体可以替换为以下内容,它在事务中运行等效的Cypher语句:
t.run(
"MERGE (n:Node {name: {name}}) SET n.size = {size}",
{"name": self.name(), "size": self.get_size()}
);