turbo_ecto v0.3.0 Turbo.Ecto
A rich ecto component, including search sort and paginate. https://hexdocs.pm/turbo_ecto
Example
Category Table Structure
Field | Type | Comment |
---|---|---|
name | string |
Product Table Structure
Field | Type | Comment |
---|---|---|
name | string | |
body | text | |
price | float | |
category_id | integer | |
available | boolean |
Variant Table Structure
Field | Type | Comment |
---|---|---|
name | string | |
price | float | |
product_id | integer |
- Input Search
url_query = http://localhost:4000/varinats?q[product_name_or_name_like]=elixir
- Expect output:
iex> params = %{"q" => %{"product.name_or_name_like" => "elixir"}}
iex> Turbo.Ecto.turboq(Turbo.Ecto.Variant, params)
#Ecto.Query<from v in Turbo.Ecto.Variant, join: p in assoc(v, :product), where: like(p.name, "%elixir%") or like(v.name, "%elixir%"), limit: 10, offset: 0>
Link to this section Summary
Link to this section Functions
Link to this function
turbo(queryable, params, opts \\ [])
turbo(Ecto.Query.t(), Map.t(), Keyword.t()) :: Map.t()
Returns a result and pageinate info.
Example
iex> params = %{"q" => %{"name_or_product.name_like" => "elixir", "price_eq" => "1"}, "s" => "updated_at+asc", "per_page" => 5, "page" => 1}
iex> Turbo.Ecto.turbo(Turbo.Ecto.Variant, params)
%{
paginate: %{current_page: 1, per_page: 5, next_page: nil, prev_page: nil, total_count: 0, total_pages: 0},
datas: []
}
Returns processed queryable.
Example
iex> params = %{"q" => %{"name_or_body_like" => "elixir"}, "s" => "updated_at+asc", "per_page" => 5, "page" => 1}
iex> Turbo.Ecto.turboq(Turbo.Ecto.Product, params)
#Ecto.Query<from p in Turbo.Ecto.Product, where: like(p.name, "%elixir%") or like(p.body, "%elixir%"), order_by: [asc: p.updated_at], limit: 5, offset: 0>