编程语言
首页 > 编程语言> > python – Neo4J / py2neo – 在事务中创建`Relationship`?

python – Neo4J / py2neo – 在事务中创建`Relationship`?

作者:互联网

在交易之外,我可以这样做:

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

我可以在交易中做类似的事吗?:

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

或者我是否必须手动将其写为密码查询?

解决方法:

好的,我知道了.

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()

标签:py2neo,python,neo4j
来源: https://codeday.me/bug/20190830/1765678.html