简体   繁体   English

Neo4J / py2neo - 在交易中创建“关系”?

[英]Neo4J / py2neo — create `Relationship` in transaction?

Outside of a transaction I can do this: 在交易之外,我可以这样做:

from py2neo import Graph, Node, Relationship
graph = Graph()
graph.create(Relationship(node1, "LINKS_TO", node2))

Can I do something analogous inside a transaction?: 我可以在交易中做类似的事吗?:

tx = graph.cypher.begin()
tx.append(Relationship(node1, "LINKS_TO", node2))  # This doesn't work

Or do I have to manually write it out as a cypher query? 或者我是否必须手动将其写为密码查询?

Ok, got it. 好的,我知道了。

from py2neo import Graph, Relationship
from py2neo.cypher import CreateStatement

graph = Graph()
tx = graph.cypher.begin()

statement = CreateStatement(graph)
statement.create(Relationship(node1, "LINKS_TO", node2))
tx.append(statement)

tx.commit()

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

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