| 296 | |
| 297 | |
| 298 | async 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 | |
| 322 | async def aggregations(): |