FatEcto v0.5.0 Paginator View Source
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
Link to this section Summary
Functions
Paginate the records.
Link to this section Functions
Paginate the records.
Parameters
query
- Ecto Queryable that represents your schema name, table name or query.params
- limit and skip values.
Examples
iex> query_opts = %{
...> "$select" => %{
...> "$fields" => ["name", "location", "rating"]
...> },
...> "$where" => %{
...> "name" => "%John%",
...> "location" => nil,
...> "rating" => "$not_null",
...> "total_staff" => %{"$between" => [1, 3]}
...> }
...> }
iex> query = Elixir.MyApp.Query.build!(FatEcto.FatHospital, query_opts)
iex> result = Elixir.Paginator.paginate(query, [limit: 10, skip: 0])
iex> %{count_query: count_query, data_query: data_query, limit: limit, skip: skip} = result
iex> limit
10
iex> skip
0
iex> count_query
#Ecto.Query<from f0 in FatEcto.FatHospital, where: f0.total_staff > ^1 and f0.total_staff < ^3 and (not(is_nil(f0.rating)) and (f0.name == ^"%John%" and (is_nil(f0.location) and ^true))), distinct: true>
iex> data_query
#Ecto.Query<from f0 in FatEcto.FatHospital, where: f0.total_staff > ^1 and f0.total_staff < ^3 and (not(is_nil(f0.rating)) and (f0.name == ^"%John%" and (is_nil(f0.location) and ^true))), limit: ^10, offset: ^0, select: map(f0, [:name, :location, :rating])>