How to fetch more than 1000?

后端 未结 16 1974
囚心锁ツ
囚心锁ツ 2020-11-28 04:13

How can I fetch more than 1000 record from data store and put all in one single list to pass to django?

16条回答
  •  清酒与你
    2020-11-28 04:34

    If you're using NDB:

    @staticmethod
    def _iterate_table(table, chunk_size=200):
        offset = 0
        while True:
            results = table.query().order(table.key).fetch(chunk_size + 1, offset=offset)
            if not results:
                break
            for result in results[:chunk_size]:
                yield result
            if len(results) < chunk_size + 1:
                break
            offset += chunk_size
    

提交回复
热议问题