Turbo Ecto

Build 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.1.7"}
]
end
config :turbo_ecto, Turbo.Ecto,
repo: MyApp.Repo,
per_page: 10

Examples

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

Also supports:

More example pls move: docs

Search Matchers

List of all possible predicates

PredicateDescriptionFinishNote
*_eqequalY(SQL: col = 'value')
*_not_eqnot equalN(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 emptyNOnly compatible with string columns. Example: q[name_present]=1 (SQL: col is not null AND col != '')
*_is_nullis null true or falseN(SQL: col is null or col is not null)
*_inmatch any values in arrayNe.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%')
*_is_trueis true or falseN(SQL: col is true or col is false)
*_betweenbegin < between < endNe.g. q[price_between][]=100&q[price_between][]=200 (SQL: 100 <= price <= 200)

Credits