All Projects → drewolson → Scrivener_ecto

drewolson / Scrivener_ecto

Licence: mit
Paginate your Ecto queries with Scrivener

Programming Languages

elixir
2628 projects

Labels

Projects that are alternatives of or similar to Scrivener ecto

ecto conditionals
EctoConditionals implements a flexibly functional find_or_create and upsert behavior for Ecto models.
Stars: ✭ 17 (-96.23%)
Mutual labels:  ecto
flop
Filtering, ordering and pagination for Ecto
Stars: ✭ 56 (-87.58%)
Mutual labels:  ecto
Crecto
Database wrapper and ORM for Crystal, inspired by Ecto
Stars: ✭ 325 (-27.94%)
Mutual labels:  ecto
bourne
🚤 Better streaming for Ecto.
Stars: ✭ 71 (-84.26%)
Mutual labels:  ecto
commanded-ecto-projections
Read model projections for Commanded using Ecto
Stars: ✭ 68 (-84.92%)
Mutual labels:  ecto
ecto autoslug field
Automatically create slugs for Ecto schemas.
Stars: ✭ 138 (-69.4%)
Mutual labels:  ecto
guardian trackable
A Guardian hook to track user sign ins.
Stars: ✭ 25 (-94.46%)
Mutual labels:  ecto
Paper trail
Track and record all the changes in your database with Ecto. Revert back to anytime in history.
Stars: ✭ 380 (-15.74%)
Mutual labels:  ecto
ecto generator
Generate Ecto schemas from existing database in Phoenix - Elixir
Stars: ✭ 20 (-95.57%)
Mutual labels:  ecto
Mongodb ecto
MongoDB adapter for Ecto
Stars: ✭ 318 (-29.49%)
Mutual labels:  ecto
txbox
Elixir Bitcoin transaction storage schema, built on Ecto.
Stars: ✭ 14 (-96.9%)
Mutual labels:  ecto
comeonin ecto password
Ecto type for saving encrypted passwords using Comeonin
Stars: ✭ 34 (-92.46%)
Mutual labels:  ecto
one plus n detector
Elixir library to help you detect 1+n queries in applications using Ecto
Stars: ✭ 20 (-95.57%)
Mutual labels:  ecto
ex sieve
Implement dynamic filtering and sorting API for Ecto queries
Stars: ✭ 37 (-91.8%)
Mutual labels:  ecto
Machinery
State machine thin layer for structs (+ GUI for Phoenix apps)
Stars: ✭ 367 (-18.63%)
Mutual labels:  ecto
ecto commons
Ecto common validators for Date, Time, URLs, Emails, PostalCodes, Phone Numbers, Luhn checks, etc.
Stars: ✭ 33 (-92.68%)
Mutual labels:  ecto
ecto diff
Generates a data structure describing the difference between two ecto structs
Stars: ✭ 22 (-95.12%)
Mutual labels:  ecto
Cloak
Elixir encryption library designed for Ecto
Stars: ✭ 413 (-8.43%)
Mutual labels:  ecto
Paginator
Cursor-based pagination for Elixir Ecto
Stars: ✭ 374 (-17.07%)
Mutual labels:  ecto
Triplex
Database multitenancy for Elixir applications!
Stars: ✭ 261 (-42.13%)
Mutual labels:  ecto

Scrivener.Ecto

Build Status Hex Version Hex docs

Low Maintenance Warning

This library is in low maintenance mode, which means the author is currently only responding to pull requests and breaking issues.

Usage

Scrivener.Ecto allows you to paginate your Ecto queries with Scrivener. It gives you useful information such as the total number of pages, the current page, and the current page's entries. It works nicely with Phoenix as well.

First, you'll want to use Scrivener in your application's Ecto Repo. This will add a paginate function to your Repo. This paginate function expects to be called with, at a minimum, an Ecto query. It will then paginate the query and execute it, returning a Scrivener.Page. Defaults for page_size can be configured when you use Scrivener. If no page_size is provided, Scrivener will use 10 by default.

You may also want to call paginate with a params map along with your query. If provided with a params map, Scrivener will use the values in the keys "page" and "page_size" before using any configured defaults.

Note: Scrivener.Ecto only supports Ecto backends that allow subqueries (e.g. PostgreSQL).

Example

defmodule MyApp.Repo do
  use Ecto.Repo, otp_app: :my_app, adapter: Ecto.Adapters.Postgres
  use Scrivener, page_size: 10
end
defmodule MyApp.Person do
  use Ecto.Schema

  schema "people" do
    field :name, :string
    field :age, :integer

    has_many :friends, MyApp.Person
  end
end
def index(conn, params) do
  page =
    MyApp.Person
    |> where([p], p.age > 30)
    |> order_by(desc: :age)
    |> preload(:friends)
    |> MyApp.Repo.paginate(params)

  render conn, :index,
    people: page.entries,
    page_number: page.page_number,
    page_size: page.page_size,
    total_pages: page.total_pages,
    total_entries: page.total_entries
end
page =
  MyApp.Person
  |> where([p], p.age > 30)
  |> order_by(desc: :age)
  |> preload(:friends)
  |> MyApp.Repo.paginate(page: 2, page_size: 5)

Installation

Add scrivener_ecto to your mix.exs deps.

defp deps do
  [
    {:scrivener_ecto, "~> 2.0"}
  ]
end

Contributing

First, you'll need to build the test database.

MIX_ENV=test mix db.reset

This task assumes you have postgres installed and that the postgres user can create / drop databases. If you'd prefer to use a different user, you can specify it with the environment variable SCRIVENER_ECTO_DB_USER.

With the database built, you can now run the tests.

mix test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].