简体   繁体   中英

How to pagination many entities in ndb [GAE / Python]

I want to get a page in many entities.

the model is 10000 entities,
I want to get a index 5000.

entities = Model.query().fetch(10, offset=5000)

but, this is anti pattern.

use cursor pattern,

entities, cursor, more = Model.query().fetch_page(10) // 0〜10
entities, cursor, more = Model.query.fetch_page(10, start_cursor=cursor) // 10〜20

this is get a start cursor.

cursor = ??? // how to get a cursor start index 5000.

i want to get a cursor.
Is this a good Idea?

I don't think GAE support random access, that is why you need offset. I don't understand your question, you know the cursor pattern and it already returns the cursor. I think cursor is meant for paging, and offset is in general to skip some entities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM