Chunkr.Pagination (Chunkr v0.2.1) View Source
Generic pagination functions.
This module provides generic pagination functions that are not specific to Ecto.
Under the hood, they delegate to whatever :planner
is configured in the call to
use Chunkr, planner: YourApp.PaginationPlanner
.
The expected usage is that the module referenced by the :planner
opt will itself
use Chunkr.PaginationPlanner
, which provides macros to automically implement the
functions necessary to extend your original query with Ecto-based filtering, sorting,
limiting, and field selection.
Note that you'll generally want to call the paginate/4
or paginate!/4
convenience
functions on your Repo module and not directly on this module. That way, you'll
automatically inherit any configuration provided in your call to use Chunkr
.
Link to this section Summary
Functions
Paginates a query in sort_dir
using your predefined strategy
.
Same as paginate/4
, but raises an error for invalid input.
Link to this section Functions
Specs
paginate(any(), atom(), Chunkr.Opts.sort_dir(), keyword()) :: {:error, String.t()} | {:ok, Chunkr.Page.t()}
Paginates a query in sort_dir
using your predefined strategy
.
The sort_dir
you specify aligns with the primary sort direction of your pagination strategy.
However, you can also provide the inverse sort direction from what your pagination strategy
specifies, and the entire sort strategy will automically be inverted.
The query must not be ordered before calling paginate/4
as the proper ordering will be
automatically applied per the registered strategy.
Options
:first
— Retrieve the first n results; must be between0
and:max_limit
.:last
— Retrieve the last n results; must be between0
and:max_limit
.:after
— Return results starting after the provided cursor; optionally pairs with:first
.:before
— Return results ending at the provided cursor; optionally pairs with:last
.:max_limit
— Maximum number of results the user can request for this query. Default is 100.:repo
— Repo to use for querying (automatically passed when calling either of the paginate convenience functions on your Repo).:planner
— The module implementing your pagination strategy (automatically passed when calling either of the paginate convenience functions on your Repo).
Specs
paginate!(any(), atom(), Chunkr.Opts.sort_dir(), keyword()) :: Chunkr.Page.t()
Same as paginate/4
, but raises an error for invalid input.