使用Python中的Google App Engine中的实体键名进行过滤 [英] Filtering by entity key name in Google App Engine on Python

查看:95
本文介绍了使用Python中的Google App Engine中的实体键名进行过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google App Engine上用Python查询数据存储,可以使用GQL或Entity.all(),然后对其进行过滤。因此,例如这些是等价的

  gql =SELECT * FROM用户WHERE年龄> = 18
db。 GqlQuery(gql)



<$ p $ ($ age $ gt; $ 18)
$ / code>

query = User.all()
query.filter

现在,也可以通过键名查询事物。我知道在GQL中你是这样做的

  gql =SELECT * FROM User WHERE __key__> = Key('User ','abc')
db.GqlQuery(gql)

但是,您会如何现在使用过滤器来做同样的事情?

  query = User.all()
query.filter(__ key__> ; =,?????)


解决方案

  from google.appengine.api.datastore import key 
query.filter(__ key__> =,Key.from_path('User','abc'))


On Google App Engine to query the data store with Python, one can use GQL or Entity.all() and then filter it. So for example these are equivalent

gql = "SELECT * FROM User WHERE age >= 18"
db.GqlQuery(gql)

and

query = User.all()
query.filter("age >=", 18)

Now, it's also possible to query things by key name. I know that in GQL you do it like this

gql = "SELECT * FROM User WHERE __key__ >= Key('User', 'abc')"
db.GqlQuery(gql)

But how would you now use filter to do the same?

query = User.all()
query.filter("__key__ >=", ?????)

解决方案

from google.appengine.api.datastore import Key
query.filter("__key__ >=", Key.from_path('User', 'abc'))

这篇关于使用Python中的Google App Engine中的实体键名进行过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆