Rummage.Ecto

Build StatusCoverage StatusHex Versionhex.pm downloadsHex docsdocsMIT licensed

If you're looking for full Phoenix support, Rummage.Phoenix uses Rumamge.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 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 Rumamge.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 implementations of Rummage, but like the other two, you can configure Rummage to not use it.

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

Installation

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

Configuration (Optional, If no configuration is provided Rummage will use default hooks)

Usage

Rummage.Ecto comes with a lot of powerful features which are available right away, without writing a bunch of code. Below are the ways Rummage.Ecto can be used:

Basic Usage:

  config :rummage_ecto, Rummage.Ecto,
    default_repo: MyApp.Repo,
    default_per_page: 10
  defmodule MyApp.Product do
    use MyApp.Web, :model
    use Rummage.Ecto

    # More code below....
  end

Advanced Usage:

Usage ( not after 0.6.0 )

  rummage = %{
    "search" => %{"name" => "value1", "category" => "value2"},
    "sort" => "name.desc",
    "paginate" => %{"per_page" => "5", "page" => "1"}
  }

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

  products = queryable
  |> Product.another_operation # <-- Since `Rummage` is Ecto, we can pipe the result queryable into another queryable operation.
  |> Repo.all
  %{
      "search" => %{"name" => "value1", "category" => "value2"},
      "sort" => "name.desc",
      "paginate" => %{"per_page" => "5", "page" => "1"}
    }