how to fetch list by order? and how to paginate just like: page, size
mouday opened this issue · comments
how?
i want to fetch list order by create_time, and fetch list by paginate is not [offset, limit]
Hi @mouday, unfortunately this is not available to the fetch
method; we support queries, but the sorting will have to be done by the app code itself.
i wish support ,thank you
@mouday I found some sort of a workaround that lets you implement pagination. Will soon write some sort of tutorial for it.
First of all it's very important to mention that delta sorted the keys alphabetically. This means we can't use a random method to generate a key. Instead I used some sort of trick to insert a new entry before the latest key. The method below generates a key that will be always inserted into the top of the Deta Base collection.
def time_key():
return 100000000000000 - int(time.time())
Second we can make use with the _fetch method that lets you use last as some sort of lookup. By doing this you only need to keep track somewhere else what was your last key in the requests.
If you want to overengineer it, it's also possible to write a cron job that counts all the collections within deta base and store the result into a paging deta base.
I'm not a deta developer so it would be great if someone of the team can approve this solution. 😊