Home

Awesome

Rummage.Ecto

<img src="src/rummage_logo.png" alt="https://hexdocs.pm/rummage_ecto/Rummage.Ecto.html" width="150" height="150">

Build Status Coverage Status Hex Version hex.pm downloads Hex docs docs MIT licensed

If you're looking for full Phoenix support, Rummage.Phoenix uses Rummage.Ecto and adds HTML and Controller support to it. You can check Rummage.Phoenix out by clicking here

Please refer for CHANGELOG for version specific changes

Rummage.Ecto is a light weight, but powerful framework that can be used to alter Ecto queries with Search, Sort and Paginate operations.

It accomplishes the above operations by using Hooks, which are modules that implement Rummage.Ecto.Hook behavior. Each operation: Search, Sort and Paginate have their hooks defined in Rummage. By doing this, Rummage is completely configurable.

For example, if you don't like one of the hooks of Rummage, but you do like the other two, you can configure Rummage to not use it and write your own custom hook.

NOTE: Rummage is not like Ransack, and it doesn't intend to be like Ransack. It doesn't define functions based on search parameters. If you'd like to have something like that, you can always configure Rummage to use your Search module for that model. This is why Rummage has been made configurable.

To see an example usage of rummage, check this repository.

Installation

This package is available in Hex, and can be installed as:

Blogs

Current Blogs:

Coming up next:

Hooks

Configuration

Usage

Rummage.Ecto comes with a lot of powerful features which are available right away, without writing a whole lot of code.

Below are the ways Rummage.Ecto can be used:

Basic Usage:

config :rummage_ecto, Rummage.Ecto,
  repo: MyApp.Repo,
  per_page: 10

Advanced Usage:

config :rummage_ecto, Rummage.Ecto,
  repo: MyApp.Repo,
  search: MyApp.SearchModule,
  paginate: MyApp.PaginateModule
{queryable, rummage} = Product
  |> Rummage.Ecto.rummage(rummage, repo: MyApp.Repo2)

Examples

rummage = %{
  search: %{field_1 => %{search_type: :like, search_term: "field_!"}},
  sort: %{field: :field1, order: :asc},
  paginate: %{per_page: 5, page: 1}
}

{queryable, rummage} = Product
  |> Rummage.Ecto.rummage(rummage)

products = queryable
  |> Product.another_operation # <-- Since `Rummage` is Ecto, we can pipe the result queryable into another queryable operation.
  |> Repo.all
rummage = %{
  search: %{field_1 => %{search_type: :like, search_term: "field_!"}},
  sort: %{field: :field1, order: :asc},
  paginate: %{per_page: 5, page: 1}
}