Turbo Ecto

Build StatusCoverage Status

Turbo is a very rich ecto component,including search sort and paginate. Inspiration by ruby ransack and learn from rummage_ecto

Phoenix support turbo_html, check this repos.

Table of contents

Getting started

def deps do
[
{:turbo_ecto, "~> 0.2.1"}
]
end
config :turbo_ecto, Turbo.Ecto,
repo: MyApp.Repo,
per_page: 10

Examples

iex> params = %{"q" => %{"name_and_category.name_like" => "elixir"}, "s" => "inserted_at+asc", "per_page" => 20}
iex> Turbo.Ecto.turboq(Turbo.Ecto.Product, params)
#Ecto.Query<from p in Turbo.Ecto.Product, join: c in assoc(p, :category),
where: like(p.name, "%elixir%") and like(c.name, "%elixir%"),
order_by: [asc: p.inserted_at], limit: 20, offset: 0>
iex> Turbo.Ecto.turbo(Turbo.Ecto.Product, params)
%{
datas: [%Product{}],
paginate: %{
current_page: 10,
next_page: 11,
per_page: 20,
prev_page: 9,
total_count: 100,
total_pages: 20
}
}

More example pls move: docs

Search Matchers

List of all possible search_types

PredicateDescriptionFinishNote
*_eqequalY(SQL: col = 'value')
*_not_eqnot equalY(SQL: col != 'value')
*_ltless thanY(SQL: col < 1024)
*_lteqless than or equalY(SQL: col <= 1024)
*_gtgreater thanY(SQL: col > 1024)
*_gteqgreater than or equalYgreater than or equal. (SQL: col >= 1024)
*_presentnot null and not emptyYOnly compatible with string columns. Example: q[name_present]=1 (SQL: col is not null AND col != '')
*_nullis null true or falseY(SQL: col is null or col is not null)
*_inmatch any values in arrayYe.g. q[name_in][]=Alice&q[name_in][]=Bob (SQL: name in ('Alice', 'Bob'))
*_likeContains valueY(SQL: col LIKE '%value%')
*_ilikeContains any ofY(SQL: col ILIKE '%value%')
*_trueis true or falseY(SQL: col is true or col is false)
*_betweenbegin < between < endYe.g. q[price_between][]=100&q[price_between][]=200 (SQL: 100 <= price <= 200)

Demo

The dummy app shows a simple turbo_ecto example.

Clone the repository.

https://github.com/zven21/turbo_ecto.git

Change directory

$ cd dummy

Run mix

$ mix deps.get

Preparing database

$ mix ecto.setup

Start the Phoenix server

$ ./script/server

Open your browser, and visit http://localhost:4000

Credits