An wrapper around Paginator.
Decorates the result returned from the Paginator by following
the Tap Giants data conventions.
All provided functions from the Paginator package are available via PaginatorTG package.
The package can be installed by adding paginator_tg to your list of dependencies in mix.exs:
def deps do
[
{:paginator_tg, "~> 0.1.1"}
]
end- Add
PaginatorTGto your repo.
defmodule MyApp.Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.Postgres
use PaginatorTG
end- Use the
paginate_tg/2function to paginate your queries.
## Simple example
query = from(ind in Industry, order_by: [desc: ind.inserted_at, desc: ind.id])
%{
list: list,
total_count: total_count,
page_info: %{
start_cursor: start_cursor,
end_cursor: end_cursor,
has_next_page: _has_next_page,
has_previous_page: _has_previous_page,
}
} = Repo.paginate_tg(query, cursor_fields: [:inserted_at, :id], first: 30)
## Example with cursors
query = from(ind in Industry, order_by: [desc: ind.inserted_at, desc: ind.id])
%{
list: list,
total_count: total_count,
page_info: %{
start_cursor: start_cursor,
end_cursor: end_cursor,
has_next_page: _has_next_page,
has_previous_page: _has_previous_page,
}
} = Repo.paginate_tg(query, cursor_fields: [:inserted_at, :id], first: 30)
query = from(ind in Industry, order_by: [desc: ind.inserted_at, desc: ind.id])
Repo.paginate_tg(
query,
after: end_cursor,
first: 30,
cursor_fields: [:inserted_at, :id]
)- Better documentation
- Development section
- License