对数据存储使用OR或IN
这是我正在运行以获取实体的查询
- ./app-demo:/dockermount under volumes
但不支持 SELECT * From Transactions
Where
__key__ = Key(Transactions,"00043b75-37f5-49c1-a104-4ebbe3f53a1atuzzin") OR
__key__ = Key(Transactions,"c0f6a0ff-97b4-42a1-8a16-5473991834c8tuzzin")
,OR
错误
获得输出的最佳方式是什么?
实体元
IN
答案 0 :(得分:1)
我们无法在OR
中使用GQL
作为per the docs。如果您知道密钥,则可以获取实体:
from google.cloud import datastore
import google.cloud.exceptions
def batch_lookup(client):
keys = [
client.key('Transactions', "00043b75-37f5-49c1-a104-4ebbe3f53a1atuzzin"),
client.key('Transactions', "c0f6a0ff-97b4-42a1-8a16-5473991834c8tuzzin")
]
result_set = []
for i in range(len(keys)):
key = keys[i]
t = client.get(key)
if t is not None:
result_set.append(t)
print(str(i + 1) + ": " + str(t))
return result_set
datastore_client = datastore.Client()
batch_lookup(datastore_client)
此示例使用提到的代码段here