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

标签 python neo4j py2neo

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

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

关于python - Neo4J/py2neo——在事务中创建 `Relationship`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28560510/

相关文章:

python - 是否可以使用 Colboratory 安装tensorflow.serving

python - 是否有 Perl 的 `study` 的 Python 等效项?

python - 使用 ESMTP 和 Twisted to GMail 发送电子邮件就在那里(没有错误或任何东西)

database - 基于图形的数据库 (http ://neo4j. org/) 的用例是什么?

python - 如何使用 matplotlib 从 numpy 列表中绘制多个数据集

neo4j - 如何通过一次查询返回多种关系类型的计数?

database - 如何浏览远程Neo4j数据库?有 REST 客户端吗?

python - 为 py2neo.error.CypherExecutionException 导入

python - py2neo (Neo4j) : py2neo. packages.httpstream.http.SocketError: 不允许操作

neo4j - 在多个 Cypher 语句中创建多个节点和关系