python 有效地翻页查询以从Google App Engine数据存储中获取所有实体。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 有效地翻页查询以从Google App Engine数据存储中获取所有实体。相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python
"""
Functions are provided for both the DB and NDB Datastore APIs.

References:
 * https://cloud.google.com/appengine/docs/python/datastore/queries
 * https://cloud.google.com/appengine/docs/python/ndb/queries
"""

def db_fetch_all(query, limit=100, cursor=None):
  """Fetch all function for the DB Datastore API."""
  results = []
  more = True
  if cursor:
    query = query.with_cursor(cursor)
  # Fetch entities in batches.
  while more:
    entities = query.fetch(limit)
    results.extend(entities)
    query = query.with_cursor(query.cursor())
    more = bool(entities)
  return results


def ndb_fetch_all(query, limit=100, cursor=None):
  """Fetch all function for the NDB Datastore API."""
  results = []
  more = True
  # Fetch entities in batches.
  while more:
    entities, cursor, more = query.fetch_page(limit, start_cursor=cursor)
    results.extend(entities)
  return results

以上是关于python 有效地翻页查询以从Google App Engine数据存储中获取所有实体。的主要内容,如果未能解决你的问题,请参考以下文章

查询 Python 字典以从元组中获取值

需要 Python 3.7 中的 Mysql 查询以从具有列 (table_no, is_new) 的表中选择记录

电子翻书的特点和优点,可以应用于哪里

python3 爬虫小技巧,

如何优化 google-bigquery 以从大数据表中查找最常见的类别?

使用 NavigationBar 禁用 UIScrollView 垂直滚动