27 lines
515 B
Elixir
27 lines
515 B
Elixir
defmodule Clacks.Paginator do
|
|
import Ecto.Query
|
|
|
|
def paginate(query, %{"max_id" => max_id}) do
|
|
query
|
|
|> where([a], a.id < ^max_id)
|
|
|> order_by(desc: :id)
|
|
end
|
|
|
|
def paginate(query, %{"since_id" => since_id}) do
|
|
query
|
|
|> where([a], a.id > ^since_id)
|
|
|> order_by(desc: :id)
|
|
end
|
|
|
|
def paginate(query, %{"min_id" => min_id}) do
|
|
query
|
|
|> where([a], a.id > ^min_id)
|
|
|> order_by(asc: :id)
|
|
end
|
|
|
|
def paginate(query, _params) do
|
|
query
|
|
|> order_by(desc: :id)
|
|
end
|
|
end
|