MCPcopy Index your code
hub / github.com/ormar-orm/ormar / pagination

Function pagination

examples/script_from_readme.py:298–319  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

296
297
298async def pagination():
299 # to limit number of returned rows use limit()
300 books = await Book.objects.limit(1).all()
301 assert len(books) == 1
302 assert books[0].title == "The Hobbit"
303
304 # to offset number of returned rows use offset()
305 books = await Book.objects.limit(1).offset(1).all()
306 assert len(books) == 1
307 assert books[0].title == "The Lord of the Rings"
308
309 # alternatively use paginate that combines both
310 books = await Book.objects.paginate(page=2, page_size=2).all()
311 assert len(books) == 2
312 # note that we removed one book of Sapkowski in delete()
313 # and recreated The Silmarillion - by default when no order_by is set
314 # ordering sorts by primary_key column
315 assert books[0].title == "The Witcher"
316 assert books[1].title == "The Silmarillion"
317
318 # to read more about pagination and number of rows
319 # visit: https://collerek.github.io/ormar/queries/pagination-and-rows-number/
320
321
322async def aggregations():

Callers

nothing calls this directly

Calls 4

allMethod · 0.45
limitMethod · 0.45
offsetMethod · 0.45
paginateMethod · 0.45

Tested by

no test coverage detected