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

You can also define other configurations with entry_name and pagenate_name in config.exs.

Examples

iex> params = %{"q" => %{"name_and_category_name_like" => "elixir"}, "s" => "inserted_at+asc", "page" = 0, "per_page" => 20}
iex> Turbo.Ecto.turbo(Turbo.Ecto.Schemas.Post, params)
%{
datas: [%Turbo.Ecto.Schemas.Post{}],
paginate: %{
current_page: 10,
next_page: 11,
per_page: 20,
prev_page: 9,
total_count: 100,
total_pages: 20
}
}

The 2 more commonly used api are as follows:

Turbo.Ecto.turbo(queryable, params, opts \\ [])

Turbo.Ecto.turboq(queryable, params, opts)

Returns an Ecto.Query.t() object

More example pls move: docs

Search Matchers

List of all possible search_types

PredicateDescriptionNote
*_eqequal(SQL: col = 'value')
*_not_eqnot equal(SQL: col != 'value')
*_ltless than(SQL: col < 1024)
*_lteqless than or equal(SQL: col <= 1024)
*_gtgreater than(SQL: col > 1024)
*_gteqgreater than or equalgreater than or equal. (SQL: col >= 1024)
*_is_presentnot null and not emptyOnly compatible with string columns. Example: q[name_present]=1 (SQL: col is not null AND col != '')
*_is_nullis null true or false(SQL: col is null or col is not null)
*_likecontains value(SQL: col LIKE '%value%')
*_ilikecontains any of(SQL: col ILIKE '%value%')
*_is_trueis true or false(SQL: col is true or col is false)
*_is_not_trueis true or falseSQL: col is not true or col is false
*_is_falseis true or falseSQL: col is false
*_is_not_falseis true or falseSQL: col is not false
*_is_nullis nullSQL: col is nil
*_is_not_nullis not null
*_inmatch any values in arraye.g. q[name_in][]=Alice&q[name_in][]=Bob (SQL: name in ('Alice', 'Bob'))
*_not_innot continasSQL: col not in ('Alice', 'Bob')
*_start_withstart with values(SQL: col LIKE '%value')
*_not_start_withnot start with values(SQL: col not LIKE '%value')
*_end_withend with values(SQL: col LIKE 'value%')
*_not_end_withnot end with valuese.g. q[name_not_end_with][]=Alice (SQL: col not LIKE 'value%')
*_betweenbegin < between < ende.g. q[price_between][]=100&q[price_between][]=200 (SQL: 100 <= price and price <= 200)

Contributing

Bug report or pull request are welcome.

Make a pull request

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Please write unit test with your code if necessary.

License

The gem is available as open source under the terms of the MIT License.

Credits