简体   繁体   English

使用py2neo事务更改节点属性

[英]Change Node properties with py2neo transaction

I'm trying to update a node using py2neo as part of a transaction. 我正在尝试使用py2neo作为事务的一部分更新节点。

The problem is I can't seem to find an equivalent of Graph.push() such as Transaction.Push() . 问题是我似乎找不到Graph.push()的等效项,例如Transaction.Push() Am I missing something obvious? 我是否缺少明显的东西?

My code at the moment looks like this, I'd like to resolve the obvious ???? 目前我的代码如下所示,我想解决明显的问题???? bit. 位。

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 )

As a use-case point, I'm using the transaction because it appears to run faster for 1000s of operations, not because I require roll-back functionality. 作为一个用例,我使用事务是因为它看起来可以在执行数千次操作时运行得更快,而不是因为我需要回滚功能。

Your entire method body can be replaced by the following, which runs the equivalent Cypher statement within the transaction: 您的整个方法主体可以替换为以下内容,该内容在事务中运行等效的Cypher语句:

t.run(
  "MERGE (n:Node {name: {name}}) SET n.size = {size}",
  {"name": self.name(), "size": self.get_size()}
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM