# Ecto.CursorPagination
[![Hex pm](](
[![Build Status](](

Cursor Pagination

Good Explanation of why cursor pagination is superior to offset/limit:


## Installation

If [available in Hex](, the package can be installed as:

  1. Add `ecto_cursor_pagination` to your list of dependencies in `mix.exs`:

    def deps do
      [{:ecto_cursor_pagination, "~> 0.1.0"}]

  2. Ensure `ecto_cursor_pagination` is started before your application:

    def application do
      [applications: [:ecto_cursor_pagination]]

### Recommended Setup
  * Configure this application
    * Add to your `config/config.exs` or each `config/env_name.exs`:

            config :ecto_cursor_pagination,
              per_page: 15,
              cursor_id: :id

## Example controller Action

    def index(conn, params) do
      last_seen_param = Map.get(params, "last_seen_id", "")
      direction_param = Map.get(params, "dir", "")

      query = Todo
              |> filter_by_uuid("user_id", params["user_id"])
              |> filter_by_string("name", params["name"])
              |> filter_by_string("type", params["type"])
      query = Ecto.CursorPagination.paginate(query, last_seen_param, direction_param)

      render(conn, "index.json", data: MyApp.Repo.all(query))

## Contributing
Before submitting your pull request, please run:
  * `mix credo --strict`
  * `mix coveralls`
  * `mix dialyzer`

Please squash your pull request's commits into a single commit with a message and
detailed description explaining the commit.