Rumamge.Ecto v0.1.1 Rummage.Ecto.Hooks.Paginate
Rummage.Ecto.Hooks.Paginate is the default pagination hook that comes shipped
with Rummage.
This module can be overridden with a custom module while using Rummage.Ecto
in Ecto struct module.
Summary
Functions
Builds a paginate query on top of the given query from the rummage parameters
from the given rummage struct
Functions
Builds a paginate query on top of the given query from the rummage parameters
from the given rummage struct.
Examples
When rummage struct passed doesn’t have the key “paginate”, it simply returns the query itself:
iex> alias Rummage.Ecto.Hooks.Paginate
iex> import Ecto.Query
iex> Paginate.run(Parent, %{}, nil)
Parent
When the query passed is not just a struct:
iex> alias Rummage.Ecto.Hooks.Paginate
iex> import Ecto.Query
iex> query = from u in "parents"
#Ecto.Query<from p in "parents">
iex> Paginate.run(query, %{}, nil)
#Ecto.Query<from p in "parents">
When rummage struct passed has the key “paginate”, with “per_page” and “page” keys it returns a paginated version of the query passed in as the argument:
iex> alias Rummage.Ecto.Hooks.Paginate
iex> import Ecto.Query
iex> rummage = %{"paginate" => %{"per_page" => "1", "page" => "1"}}
%{"paginate" => %{"page" => "1", "per_page" => "1"}}
iex> query = from u in "parents"
#Ecto.Query<from p in "parents">
iex> Paginate.run(query, rummage, nil)
#Ecto.Query<from p in "parents", limit: ^1, offset: ^0>