Skip to content

Commit

Permalink
Merge pull request #58 from aditya7iyengar/v1.3.0
Browse files Browse the repository at this point in the history
Revamp 1.3.0
  • Loading branch information
Adi Iyengar authored May 30, 2018
2 parents d368546 + 8cca28e commit 5267970
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ otp_release:
- 20.2
sudo: false
env:
- MIX_ENV=test ECTO_PGSQL_USER=postgres ECTO_PGSQL_PASSWORD=
- MIX_ENV=test POSTGRES_USERNAME=postgres POSTGRES_PASSWORD=
script:
- mix test
after_script:
Expand Down
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Rummage.Ecto

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

[![Build Status](https://travis-ci.org/aditya7iyengar/rummage_ecto.svg?branch=master)](https://travis-ci.org/aditya7iyengar/rummage_ecto)
[![Coverage Status](https://coveralls.io/repos/github/aditya7iyengar/rummage_ecto/badge.svg?branch=master)](https://coveralls.io/github/aditya7iyengar/rummage_ecto?branch=master)
[![Hex Version](http://img.shields.io/hexpm/v/rummage_ecto.svg?style=flat)](https://hex.pm/packages/rummage_ecto)
Expand All @@ -26,6 +28,8 @@ hook.
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](https://github.com/aditya7iyengar/rummage_ecto_example) repository.

## Installation

This package is [available in Hex](https://hexdocs.pm/rummage_ecto/), and can be installed as:
Expand All @@ -34,7 +38,7 @@ This package is [available in Hex](https://hexdocs.pm/rummage_ecto/), and can be

```elixir
def deps do
[{:rummage_ecto, "~> 1.2.0"}]
[{:rummage_ecto, "~> 1.3"}]
end
```

Expand All @@ -53,12 +57,14 @@ This package is [available in Hex](https://hexdocs.pm/rummage_ecto/), and can be
- Using the Rummage Sort hook
- Writing a Custom Rummage.Ecto Hook
- Writing a Custom Rummage.Phoenix HTML helper
- Using Rummage with other Libraries: Kerosene
- Using Rummage with other Libraries: Scrivener

## Hooks


- Hooks are modules (that use `Rummage.Ecto.Hook`) and implement callbacks for
`Rummage.Ecto.Hook` behaviour. Each ecto operation which can transform the
query is defined by a `Hook`. Hooks have `run/2` function using which they
can transform an `Ecto.Queryable` variable and have `format_params/3` function
using which they can transform params passed to them through `rummage_ecto`


## Configuration
Expand Down Expand Up @@ -90,7 +96,9 @@ This package is [available in Hex](https://hexdocs.pm/rummage_ecto/), and can be

## Usage

`Rummage.Ecto` comes with a lot of powerful features which are available right away, without writing a whole lot of code.
`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:
Expand Down Expand Up @@ -134,9 +142,9 @@ Below are the ways `Rummage.Ecto` can be used:

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

{queryable, rummage} = Product
Expand All @@ -151,29 +159,21 @@ Below are the ways `Rummage.Ecto` can be used:
If invalid keys are passed, they won't alter any operations in rummage. Here's an example of `Rummage` params:

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

## Example with Screenshots

- Rummage Search example:
![rummage search](src/rummage_search.png)

- Rummage Search with Association example:
![rummage search assoc](src/rummage_search_assoc.png)
- Coming soon...

- Rummage Sort example:
![rummage sort](src/rummage_sort.png)

- Rummage Sort with Association example:
![rummage sort assoc](src/rummage_sort_assoc.png)
## Next Steps

- Rummage Search with Sort example:
![rummage search sort](src/rummage_search_and_sort.png)
- [ ] Strealine associations
- [ ] `rummage_ecto` should have a custom hook to handle embedded_fields
- [ ] Continued writing blogs

- Rummage Search, Sort and Paginate example:
![rummage search sort paginate](src/rummage_search_sort_and_paginate.png)
4 changes: 3 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ config :rummage_ecto, ecto_repos: [Rummage.Ecto.Repo]

config :rummage_ecto, Rummage.Ecto.Repo,
adapter: Ecto.Adapters.Postgres,
database: "rummage_ecto_test.sqlite3",
username: System.get_env("POSTGRES_USERNAME"),
password: System.get_env("POSTGRES_PASSWORD"),
database: "rummage_ecto_test",
pool: Ecto.Adapters.SQL.Sandbox
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule Rummage.Ecto.Mixfile do
{:excoveralls, "~> 0.3", only: :test},
{:ex_doc, "~> 0.14", only: :dev, runtime: false},
{:inch_ex, "~> 0.5", only: [:dev, :test, :docs]},
{:sqlite_ecto2, "~> 2.2", only: :test},
{:postgrex, ">= 0.0.0", only: :test},
]
end

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [], [], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [], [], "hexpm"},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.13.3", "c277cfb2a9c5034d445a722494c13359e361d344ef6f25d604c2353185682bfc", [], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
"sbroker": {:hex, :sbroker, "1.0.0", "28ff1b5e58887c5098539f236307b36fe1d3edaa2acff9d6a3d17c2dcafebbd0", [], [], "hexpm"},
"sqlite_ecto2": {:hex, :sqlite_ecto2, "2.2.2", "7a3e5c0521e1cb6e30a4907ba4d952b97db9b2ab5d1a4806ceeb66a10b23ba65", [], [{:connection, "~> 1.0.3", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 2.2.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:esqlite, "~> 0.2.3", [hex: :esqlite, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: false]}, {:sqlitex, "~> 1.3.2 or ~> 1.4", [hex: :sqlitex, repo: "hexpm", optional: false]}], "hexpm"},
"sqlitex": {:hex, :sqlitex, "1.3.3", "3aac5fd702be346f71d9de6e01702c9954484cd0971aa443490bb3bde045d919", [], [{:decimal, "~> 1.1", [hex: :decimal, repo: "hexpm", optional: false]}, {:esqlite, "~> 0.2.3", [hex: :esqlite, repo: "hexpm", optional: false]}], "hexpm"},
Expand Down
Binary file added src/rummage_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/rummage_search.png
Binary file not shown.
Binary file removed src/rummage_search_and_sort.png
Binary file not shown.
Binary file removed src/rummage_search_assoc.png
Binary file not shown.
Binary file removed src/rummage_search_sort_and_paginate.png
Binary file not shown.
Binary file removed src/rummage_sort.png
Binary file not shown.
Binary file removed src/rummage_sort_assoc.png
Binary file not shown.
2 changes: 1 addition & 1 deletion test/support/repo.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
defmodule Rummage.Ecto.Repo do
use Ecto.Repo, otp_app: :rummage_ecto, adapter: Sqlite.Ecto2
use Ecto.Repo, otp_app: :rummage_ecto
end

0 comments on commit 5267970

Please sign in to comment.