Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Nebo15/ecto_paging
Cursor-based pagination for Ecto.
https://github.com/Nebo15/ecto_paging
cursor ecto elixir elixir-lang hex package pagination
Last synced: 3 months ago
JSON representation
Cursor-based pagination for Ecto.
- Host: GitHub
- URL: https://github.com/Nebo15/ecto_paging
- Owner: Nebo15
- License: mit
- Created: 2016-10-15T14:45:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-03-03T15:29:19.000Z (almost 5 years ago)
- Last Synced: 2024-10-08T14:07:56.183Z (4 months ago)
- Topics: cursor, ecto, elixir, elixir-lang, hex, package, pagination
- Language: Elixir
- Size: 83 KB
- Stars: 14
- Watchers: 14
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Cursor-based pagination for Ecto. (ORM and Datamapping)
- fucking-awesome-elixir - ecto_paging - Cursor-based pagination for Ecto. (ORM and Datamapping)
- awesome-elixir - ecto_paging - Cursor-based pagination for Ecto. (ORM and Datamapping)
README
# Ecto.Paging
[![Deps Status](https://beta.hexfaktor.org/badge/all/github/Nebo15/ecto_paging.svg)](https://beta.hexfaktor.org/github/Nebo15/ecto_paging) [![Build Status](https://travis-ci.org/Nebo15/ecto_paging.svg?branch=master)](https://travis-ci.org/Nebo15/ecto_paging) [![Coverage Status](https://coveralls.io/repos/github/Nebo15/ecto_paging/badge.svg?branch=master)](https://coveralls.io/github/Nebo15/ecto_paging?branch=master)
This module provides a easy way to apply cursor-based pagination to your Ecto Queries.
## Usage:
1. Add macro to your repo
```elixir
defmodule MyRepo do
use Ecto.Repo, otp_app: :my_app
use Ecto.Paging.Repo # This string adds `paginate/2` and `page/3` methods.
end
```2. Paginate!
```elixir
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_at` field 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_more` and `size` counts in `paginate` struct (TODO: add this helpers).
* When both `starting_after` and `ending_before` is set, only `starting_after` is used.## Installation
1. Add `ecto_paging` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:ecto_paging, "~> 0.8.4"}]
end
```2. Ensure `ecto_paging` is started before your application:
```elixir
def application do
[applications: [:ecto_paging]]
end
```