Paginator v0.2.0 Paginator behaviour View Source
Defines a paginator.
This module adds a paginate/3
function to your Ecto.Repo
so that you can
paginate through results using opaque cursors.
Usage
defmodule MyApp.Repo do
use Ecto.Repo, otp_app: :my_app
use Paginator
end
Link to this section Summary
Callbacks
Fetches all the results matching the query within the cursors
Link to this section Callbacks
Link to this callback
paginate(queryable, opts, repo_opts)
View Source
paginate( queryable :: Ecto.Query.t(), opts :: Keyword.t(), repo_opts :: Keyword.t() ) :: Paginator.Page.t()
Fetches all the results matching the query within the cursors.
Options
:after
- Fetch the records after this cursor.:before
- Fetch the records before this cursor.:cursor_fields
- The fields used to determine the cursor. In most cases, this should be the same fields as the ones used for sorting in the query.:include_total_count
- Set this to true to return the total number of records matching the query. Note that this number will be capped by:total_count_limit
. Defaults tofalse
.:limit
- Limits the number of records returned per page. Defaults to 50.:sort_direction
- The direction used for sorting. Defaults to:asc
.:total_count_limit
- Running count queries on tables with a large number of records is expensive so it is capped by default. Can be set to:infinity
in order to count all the records. Defaults to 10,000.
Repo options
This will be passed directly to Ecto.Repo.all/2
, as such any option supported
by this function can be used here.
Example
query = from(p in Post, order_by: [asc: p.inserted_at, asc: p.id], select: p)
Repo.paginate(query, cursor_fields: [:inserted_at, :id], limit: 50)