@@ -1643,6 +1643,59 @@ SELECT * from "some_model" where
16431643 order by " some_model" ." user_id" ASC , " some_model" ." post_id" ASC limit 10
16441644```
16451645
1646+ ### ` each_page(...) `
1647+
1648+ Returns an iterator function that can be used to iterate through each page of
1649+ results. Optional arguments can be provided to specify the starting point for
1650+ iteration, using the same cursor values that would be passed to ` get_page ` .
1651+
1652+ $dual_code{
1653+ moon = [[
1654+ import OrderedPaginator from require "lapis.db.pagination"
1655+ pager = OrderedPaginator Events, "id", "where user_id = ?", 123
1656+
1657+ -- iterate through all pages from the beginning
1658+ for page_results in pager\each_page!
1659+ process page_results
1660+
1661+ -- iterate starting from id > 500
1662+ for page_results in pager\each_page 500
1663+ process page_results
1664+ ]] ,
1665+ lua = [[
1666+ local OrderedPaginator = require("lapis.db.pagination").OrderedPaginator
1667+ local pager = OrderedPaginator(Events, "id", "where user_id = ?", 123)
1668+
1669+ -- iterate through all pages from the beginning
1670+ for page_results in pager: each_page () do
1671+ process(page_results)
1672+ end
1673+
1674+ -- iterate starting from id > 500
1675+ for page_results in pager: each_page (500) do
1676+ process(page_results)
1677+ end
1678+ ]] }
1679+
1680+ For composite ordering with multiple columns, pass multiple arguments:
1681+
1682+ $dual_code{
1683+ moon = [[
1684+ pager = OrderedPaginator SomeModel, {"user_id", "post_id"}
1685+
1686+ -- start from (user_id, post_id) > (100, 200)
1687+ for page_results in pager\each_page 100, 200
1688+ process page_results
1689+ ]] ,
1690+ lua = [[
1691+ local pager = OrderedPaginator(SomeModel, {"user_id", "post_id"})
1692+
1693+ -- start from (user_id, post_id) > (100, 200)
1694+ for page_results in pager: each_page (100, 200) do
1695+ process(page_results)
1696+ end
1697+ ]] }
1698+
16461699## Relations
16471700
16481701Often your models are connected to other models by use of a * foreign_key* . You
0 commit comments