【问题标题】:How to list kinds in datastore?如何列出数据存储中的种类?
【发布时间】:2016-01-01 23:09:17
【问题描述】:

我只需要为我自己的应用程序解决这个问题,所以在这里重新发布答案。

【问题讨论】:

    标签: google-app-engine


    【解决方案1】:

    自从提出并回答这个问题已经过去了。现在有一个更简单的方法。

    http://code.google.com/appengine/docs/python/datastore/metadataqueries.html

    q = Kind.all()
    for kind in q.fetch(100):
      print kind.kind_name
    

    【讨论】:

      【解决方案2】:
      def GetSchemaKinds():
          """Returns the list of kinds for this app."""
      
          class KindStatError(Exception):
            """Unable to find kind stats."""
      
          from google.appengine.ext.db import stats
          global_stat = stats.GlobalStat.all().get()
          if not global_stat:
            raise KindStatError()
          timestamp = global_stat.timestamp
          kind_stat = stats.KindStat.all().filter(
              "timestamp =", timestamp).fetch(1000)
          kind_list = [stat.kind_name for stat in kind_stat
                       if stat.kind_name and not stat.kind_name.startswith('__')]
          kind_set = set(kind_list)
          return list(kind_set) 
      

      参考:http://groups.google.com/group/google-appengine/browse_thread/thread/f2e7568040c015ff

      【讨论】:

        【解决方案3】:

        值得注意的是,此答​​案适用于较旧的db api。新的ndb api 有另一种方法来获取此处列出的所有Kind https://cloud.google.com/appengine/docs/python/ndb/metadata#get_kinds

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-09-08
          • 1970-01-01
          • 2018-06-01
          • 2016-01-30
          • 2017-02-23
          • 2019-12-01
          • 2018-07-03
          • 1970-01-01
          相关资源
          最近更新 更多