EctoTurbo (EctoTurbo v1.0.0)
View SourceA rich ecto component, including search sort and paginate.
Example
Category Table Structure
| Field | Type | Comment |
|---|---|---|
name | string |
Post Table Structure
| Field | Type | Comment |
|---|---|---|
name | string | |
body | text | |
price | float | |
category_id | integer | |
available | boolean |
Reply Table Structure
| Field | Type | Comment |
|---|---|---|
name | string | |
price | float | |
post_id | integer |
Input Search:
url_query = http://localhost:4000/repies?q[post_name_or_content_like]=elixirExpect output:
iex> EctoTurbo.turboq(EctoTurbo.Schemas.Reply, %{"q" => %{"post_name_or_content_like" => "elixir"}})
#Ecto.Query<from r0 in EctoTurbo.Schemas.Reply, join: p1 in assoc(r0, :post), where: like(p1.name, ^"%elixir%") or like(r0.content, ^"%elixir%"), limit: ^10, offset: ^0>
Summary
Functions
Returns a result and pageinate info.
Example
iex> EctoTurbo.turbo(EctoTurbo.Schemas.Post, %{"q" => %{"name_or_replies_content_like" => "elixir", "price_eq" => 1}, "s" => "updated_at+asc", "per_page" => 5, "page" => 1})
%{
pagination: %{current_page: 1, current_pages: [1], per_page: 5, next_page: nil, prev_page: nil, total_count: 0, total_pages: 0},
data: []
}
@spec turboq(any(), map()) :: Ecto.Query.t()
Returns processed queryable.
Example
iex> EctoTurbo.turboq(EctoTurbo.Schemas.Post, %{"q" => %{"name_or_body_like" => "elixir", "a_eq" => ""}, "s" => "updated_at+asc", "per_page" => 5, "page" => 1})
#Ecto.Query<from p0 in EctoTurbo.Schemas.Post, where: like(p0.name, ^"%elixir%") or like(p0.body, ^"%elixir%"), order_by: [asc: p0.updated_at], limit: ^5, offset: ^0>