【发布时间】:2020-12-13 01:42:23
【问题描述】:
我最近将我的 py2neo 库从 version V2 切换到 version V3,但我不知道执行某些操作的新命令。
特别是我坚持:
graph.merge_one
通过标签和可选属性匹配或创建一个节点并返回一个 单个匹配节点。此方法旨在与独特的 如果找到多个匹配节点,则不会失败。 (read the docs)
例如
from py2neo import Node, Graph
nicole = Node("Person", name="Nicole", age=24)
# adds the nicole element to the graph if it does not already exist a node labelled as "Person" having attribute "name" equal to "Nicole".
graph.merge_one("Person", "name", "Nicole") #<-- What's the equivalent py2neo V3 command?
graph.create_unique
在单个文件中创建一个或多个独特的路径或关系 交易。这类似于 create() 但使用 Cypher CREATE UNIQUE 子句确保只有那些还没有的关系 存在被创建。 (read the docs)
例如
from py2neo import Node, Relationship, Graph
kenny = Node("Person", name="Kenny")
graph.create(kenny)
kingfish = Node("Bar", name="Kingfish")
graph.create(kingfish)
rel = Relationship(kenny, "LIKES", kingfish)
# creates the relationship (kenny)-[:LIKES]->(kingfish), but only if it does not exist yet.
graph.create_unique(rel) #<-- What's the equivalent py2neo V3 command?
graph.find_one
通过标签和可选属性查找单个节点。这种方法是 旨在与唯一约束一起使用,如果更多则不会失败 多于一个匹配节点。 (read the docs)
例如
from py2neo import Graph
# Find one node (and take only one if there are many) matching these conditions: its type is "Person" and it has an attribute "name" equal to "Kenny", and then save it inside "kenny" variable.
kenny = graph.find_one("Person", "name", "Kenny") #<-- What's the equivalent py2neo V3 command?
我发现这些方法在 py2neo V3 中不再可用,
那么这些方法对于 py2neo V3 的等价物是什么?
【问题讨论】: