【问题标题】:Filtering by entity key name in Google App Engine on Python在 Python 上的 Google App Engine 中按实体键名过滤
【发布时间】:2011-02-02 10:14:49
【问题描述】:

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

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

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

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

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

但是你现在如何使用过滤器来做同样的事情呢?

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

【问题讨论】:

    标签: python google-app-engine google-cloud-datastore


    【解决方案1】:
    from google.appengine.api.datastore import Key
    query.filter("__key__ >=", Key.from_path('User', 'abc'))
    

    【讨论】:

      【解决方案2】:

      对我来说,类似的方法有效,而“from_path”功能在我的情况下不起作用,这个方法有效:

      from google.appengine.api.datastore import Key
      
      key = Key(your_string_with_key)
      query.filter("__key__ = ", key)
      

      【讨论】:

        猜你喜欢
        • 2012-04-27
        • 2016-06-21
        • 1970-01-01
        • 2012-04-27
        • 2010-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-25
        相关资源
        最近更新 更多