使用 py2neo OGM 进行图形查询
我正在尝试使用使用PY2NEO定义的类来运行数据库上的图形查询。到目前为止,这是我所拥有的:
py2neo.ogm import Graph, GraphObject, Property, RelatedTo, Label
gsb = Graph(address = "localhost:11004", password='<my_password>')
class Dataset(GraphObject):
__primarykey__ = 'title'
title = Property()
Dataset = Label()
class User(GraphObject):
__primarykey__ = 'user_id'
user_id = Property()
dept = Property()
email = Property()
name = Property()
eigenvector = property()
grantedAccess = RelatedTo("Dataset", "GRANTED_ACCESS_TO")
test_user = User.match(gsb, 'test_user').first()
for ds in test_user.grantedAccess:
print(ds.title)
我希望的是授予“ test_user”访问权限的数据集列表。等效的Cypher查询将是:
MATCH (a:User)-[r:GRANTED_ACCESS_TO]->(b:Dataset)
WHERE a.user_id = 'test_user'
RETURN b.title
但是当我运行Python代码时,我什么也没得到,甚至没有错误消息,只是没有结果。我知道数据库连接正常工作,并且我知道数据库中有匹配查询的关系模式。我假设我的查询以某种方式编写了吗?
谁能解释为什么我的Python代码没有返回结果?
I'm trying to use classes defined using py2neo to run graph queries on my database. Here's what I have so far:
py2neo.ogm import Graph, GraphObject, Property, RelatedTo, Label
gsb = Graph(address = "localhost:11004", password='<my_password>')
class Dataset(GraphObject):
__primarykey__ = 'title'
title = Property()
Dataset = Label()
class User(GraphObject):
__primarykey__ = 'user_id'
user_id = Property()
dept = Property()
email = Property()
name = Property()
eigenvector = property()
grantedAccess = RelatedTo("Dataset", "GRANTED_ACCESS_TO")
test_user = User.match(gsb, 'test_user').first()
for ds in test_user.grantedAccess:
print(ds.title)
What I was hoping for was a list of Datasets to which 'test_user' had been granted access. The equivalent cypher query would be:
MATCH (a:User)-[r:GRANTED_ACCESS_TO]->(b:Dataset)
WHERE a.user_id = 'test_user'
RETURN b.title
But when I run the python code I get nothing, not even an error message, just no results. I know the database connection is working correctly, and I know there are relationship patterns in the database that match the query. I'm assuming my query is written incorrectly somehow?
Can anyone explain why my python code returns no results?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,事实证明,这只是一个令人尴尬的错别字。我正在从标记为edge
granded_access_to
的数据库文档,但是在实际数据库中,它是granded_access
。一旦我做出了更改,一切都按预期工作。我将让mods决定是否值得将这个问题发布为代码示例。否则,请随时删除。
Well, it turns out this was just an embarrassing typo. The database documentation I was working from labeled the edge
GRANTED_ACCESS_TO
but in the actual database it wasGRANTED_ACCESS
. Once I made that change, everything worked as expected.I'll let the mods decided whether it's worth keeping this question posted as a code example. Otherwise, feel free to delete.