Ecto.Paging
This module provides a easy way to apply cursor-based pagination to your Ecto Queries.
Usage:
Add macro to your repo
defmodule MyRepo douse Ecto.Repo, otp_app: :my_appuse Ecto.Paging.Repo # This string adds `paginate/2` and `page/3` methods.endPaginate!
query = from p in Ecto.Paging.Schema{res, next_paging} = query|> Ecto.Paging.TestRepo.page(%Ecto.Paging{limit: 150})
Limitations:
- Right now it works only with schemas that have
:inserted_atfield with auto-generated value. - You need to be careful with order-by's in your queries, since this feature is not tested yet.
- It doesn't construct
has_moreandsizecounts inpaginatestruct (TODO: add this helpers). - When both
starting_afterandending_beforeis set, onlystarting_afteris used.
Installation
- Add
ecto_pagingto your list of dependencies inmix.exs:
```elixir
def deps do
[{:ecto_paging, "~> 0.8.3"}]
end
```
Ensure
ecto_pagingis started before your application:def application do[applications: [:ecto_paging]]end