如何在不实例化模型的情况下获取数据存储(应用程序引擎)记录?
嗨,谁能告诉我如何做到这一点,我是初学者。我尝试使用这个:
def get_entities(keys):
rpc = datastore.GetRpcFromKwargs({})
keys, multiple = datastore.NormalizeAndTypeCheckKeys(keys)
entities = None
try:
entities = datastore.Get(keys, rpc=rpc)
except datastore_errors.EntityNotFoundError:
assert not multiple
return entities
但无法在没有模型使用的情况下获取密钥。
Hi can anyone tell me how it can be done,i am a beginner. I tried using this:
def get_entities(keys):
rpc = datastore.GetRpcFromKwargs({})
keys, multiple = datastore.NormalizeAndTypeCheckKeys(keys)
entities = None
try:
entities = datastore.Get(keys, rpc=rpc)
except datastore_errors.EntityNotFoundError:
assert not multiple
return entities
but unable to get keys without the models use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的意思是您想要 datastore.Entity 对象而不是 Model 实例吗?如果是这样,假设键是一个列表,您应该能够将代码简化为:
return datastore.Get(keys)
否则,如果您只想查看哪些键在数据存储区中具有匹配的实体,试试这个:
return db.GqlQuery('SELECT __key__ FROMWHERE __key__ IN :1', keys)
替换
为您要查询的实体类型。do you mean you want datastore.Entity objects instead of Model instances? if so, assuming keys is a list, you should be able to simplify your code to this:
return datastore.Get(keys)
otherwise, if you just want to see which keys have matching entities in the datastore, try this:
return db.GqlQuery('SELECT __key__ FROM <kind> WHERE __key__ IN :1', keys)
replace
<kind>
with the kind of entity you're querying for.