View Source PaginatorDocs (FatEcto v1.0.0)

Paginator module can limit the number of records returned and also apply the offset and return meta information. You can use it inside a module.

  use FatEcto.FatPaginator, max_limit: 10, default_limit: 5

Summary

Functions

Paginates the given query with the provided parameters.

Functions

paginate(query, params)

Paginates the given query with the provided parameters.

Parameters

  • query: The Ecto query to paginate.
  • params: A keyword list or map containing limit and skip values.

Returns

A map containing:

  • data_query: The paginated query.
  • count_query: The query to count the total number of records.
  • limit: The limit value used for pagination.
  • skip: The skip value used for pagination.

Examples

iex> import Ecto.Query
iex> query = from(h in FatEcto.FatHospital)
iex> result = FatEcto.Sample.Pagination.paginate(query, limit: 10, skip: 0)
iex> %{data_query: data_query, count_query: count_query, limit: limit, skip: skip} = result
iex> limit
10
iex> skip
0
iex> data_query
#Ecto.Query<from f0 in FatEcto.FatHospital, limit: ^10, offset: ^0>
iex> count_query
#Ecto.Query<from f0 in FatEcto.FatHospital, distinct: true>