gpt4 book ai didi

python - 如何使用pyrebase查询?

转载 作者:行者123 更新时间:2023-12-05 06:14:47 27 4
gpt4 key购买 nike

我正在学习如何使用 python、django 和 pyrebase 进行查询。查询键的多个值时遇到问题。

例如:

这是我的数据结构:

    {
"root": {
"account": {
"ACC0001": {
"id": "ACC0001",
"create_day": "2020-04-20 16:56:11",
"create_by": "USE001",
"brief_name": "AAAAA",
"status": "active"
},
"ACC0002": {
"id": "ACC0002",
"create_day": "2020-04-20 16:56:12",
"create_by": "USE002",
"brief_name": "BBBBB",
"status": "inactive"
},
"ACC0003": {
"id": "ACC0003",
"create_day": "2020-04-20 16:56:13",
"create_by": "USE003",
"brief_name": "CCCCC",
"status": "active"
},
"ACC0004": {
"id": "ACC0004",
"create_day": "2020-04-20 16:56:14",
"create_by": "USE004",
"brief_name": "DDDDD",
"status": "inactive"
},
"ACC0005": {
"id": "ACC0005",
"create_day": "2020-04-20 16:56:15",
"create_by": "USE005",
"brief_name": "EEEEE",
"status": "inactive"
},

......

"ACC9999": {
"id": "ACC9999",
"create_day": "2020-04-20 16:56:15",
"create_by": "USE100",
"brief_name": "FFFFF",
"status": "active"
}
}
}
}

在 SQL 中,我使用类似“select * from AAA where D = 'active' and (I = 'USE002' or I = 'USE003' or I = 'USE004' or I = 'USE005')”我如何在 python、django 和 pyrebase 中获取列表用户的记录?我只得到一个用户。我的代码如下:

    config = {
'apiKey': "xxxxxx",
'authDomain': "xxxx.firebaseapp.com",
'databaseURL': "https://xxxx.firebaseio.com",
'projectId': "xxxx-92dec",
'storageBucket': "xxxx-92dec.appspot.com",
'messagingSenderId': "xxxx598699",
'appId': "1:xxxxx8699:web:xxxxx5a9e2920ec32e",
'measurementId': "xxxx360FN"
}

firebase = pyrebase.initialize_app(config)
database = firebase.database()
// how can get all record of list create_by ['USE001','USE002','USE003'...]
objuser = database.child('account').order_by_child('create_by').equal_to('USE001').get().val()

最佳答案

Firebase 实时数据库不允许查询 equality is checked against a list 的位置.

实现最终目标的两种方法:

为每个用户使用真值。将数据库更改为如下内容:

{
"root": {
"account": {
"ACC0001": {
"id": "ACC0001",
"create_day": "2020-04-20 16:56:11",
"create_by": "USE001",
"create_by_USE001": true,
"create_by_USE002": false,
"create_by_USE003": false,
"create_by_USE004": false,
"brief_name": "AAAAA",
"status": "active"
},
"ACC0002": {
"id": "ACC0002",
"create_day": "2020-04-20 16:56:12",
"create_by": "USE002",
"create_by_USE001": false,
"create_by_USE002": true,
"create_by_USE003": false,
"create_by_USE004": false,
"brief_name": "BBBBB",
"status": "inactive"
},
...

更好的方法是使用 firestore,因为它支持 in and array-contains-any

关于python - 如何使用pyrebase查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62751722/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com