Py2neo(V4) - AttributeError:'Graph'对象没有属性'find_one'

问题描述 投票:1回答:1

我正在尝试将neo4j-flask应用程序更新为Py2Neo V4,我无法找到“find_one”函数是如何被替换的。 (Nicole White使用了Py2Neo V2)https://nicolewhite.github.io/neo4j-flask/

https://github.com/nicolewhite/neo4j-flask

https://neo4j.com/blog/building-python-web-application-using-flask-neo4j/

我的设置:

  • Ubuntu 18.04
  • Python 3.6.5
  • Neo4j服务器版本:3.4.6(社区)

Requirements.txt(其余代码来自Nicole White的github存储库):

atomicwrites==1.2.0
attrs==18.1.0
backcall==0.1.0
bcrypt==3.1.4
certifi==2018.8.24
cffi==1.11.5
click==6.7
colorama==0.3.9
decorator==4.3.0
Flask==1.0.2
ipykernel==4.8.2
ipython==6.5.0
ipython-genutils==0.2.0
itsdangerous==0.24
jedi==0.12.1
Jinja2==2.10
jupyter-client==5.2.3
jupyter-console==5.2.0
jupyter-core==4.4.0
MarkupSafe==1.0
more-itertools==4.3.0
neo4j-driver==1.6.1
neotime==1.0.0
parso==0.3.1
passlib==1.7.1
pexpect==4.6.0
pickleshare==0.7.4
pkg-resources==0.0.0
pluggy==0.7.1
prompt-toolkit==1.0.15
ptyprocess==0.6.0
py==1.6.0
py2neo==4.1.0
pycparser==2.18
Pygments==2.2.0
pytest==3.7.3
python-dateutil==2.7.3
pytz==2018.5
pyzmq==17.1.2
simplegeneric==0.8.1
six==1.11.0
tornado==5.1
traitlets==4.3.2
urllib3==1.22
wcwidth==0.1.7
Werkzeug==0.14.1

注册用户收到错误:AttributeError:'Graph'对象没有属性'find_one'

“User.find()方法使用py2neo的Graph.find_one()方法在数据库中查找标签:User和给定用户名,返回py2neo.Node对象。”

在Py2Neo V3中,函数find_one - > https://py2neo.org/v3/database.html?highlight=find#py2neo.database.Graph.find_one可用。

在Py2Neo V4 https://py2neo.org/v4/matching.html中,找不到功能了。

有人知道如何在V4中解决它,或者正在降级这里的方式?

python flask neo4j py2neo
1个回答
2
投票

py2neo v4有一个first函数,可以与NodeMatcher一起使用。见:https://py2neo.org/v4/matching.html#py2neo.matching.NodeMatch.first

那说... v4引入了GraphObjects(至少到目前为止)我发现它非常整洁。

在链接的github示例中,创建用户:

user = Node('User', username=self.username, password=bcrypt.encrypt(password))
graph.create(user)

并找到了

user = graph.find_one('User', 'username', self.username)

在py2neo v4中,我会这样做

class User(GraphObject):
    __primarykey__ = "username"

    username = Property()
    password = Property()

 lukas = User()
 lukas.username = "lukasott"
 lukas.password = bcrypt.encrypt('somepassword')
 graph.push(lukas)

user = User.match(graph, "lukasott").first()

正如我所理解的那样,first函数提供了与q3文档引用的find_one相同的保证“并且如果找到多个匹配节点则不会失败。”

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.