Turbo.Ecto (turbo_ecto v1.0.2)

A rich ecto component, including search sort and paginate. https://hexdocs.pm/turbo_ecto

Example

Category Table Structure

FieldTypeComment
namestring

Post Table Structure

FieldTypeComment
namestring
bodytext
pricefloat
category_idinteger
availableboolean

Reply Table Structure

FieldTypeComment
namestring
pricefloat
post_idinteger
  • Input Search

    url_query = http://localhost:4000/repies?q[post_name_or_content_like]=elixir
  • Expect output:

    iex> params = %{"q" => %{"post_name_or_content_like" => "elixir"}}
    iex> Turbo.Ecto.turboq(Turbo.Ecto.Schemas.Reply, params)
    #Ecto.Query<from r0 in Turbo.Ecto.Schemas.Reply, join: p1 in assoc(r0, :post), where: like(p1.name, "%elixir%") or like(r0.content, "%elixir%"), limit: 10, offset: 0>

Link to this section Summary

Functions

Returns a result and pageinate info.

Returns processed queryable.

Link to this section Functions

Link to this function

turbo(queryable, params, opts \\ [])

Specs

turbo(any(), any(), keyword()) :: map()

Returns a result and pageinate info.

Example

iex> params = %{"q" => %{"name_or_replies_content_like" => "elixir", "price_eq" => "1"}, "s" => "updated_at+asc", "per_page" => 5, "page" => 1}
iex> Turbo.Ecto.turbo(Turbo.Ecto.Schemas.Post, params)
%{
  paginate: %{current_page: 1, per_page: 5, next_page: nil, prev_page: nil, total_count: 0, total_pages: 0},
  datas: []
}
Link to this function

turboq(queryable, params)

Specs

turboq(any(), map()) :: Ecto.Query.t()

Returns processed queryable.

Example

iex> params = %{"q" => %{"name_or_body_like" => "elixir", "a_eq" => ""}, "s" => "updated_at+asc", "per_page" => 5, "page" => 1} iex> Turbo.Ecto.turboq(Turbo.Ecto.Schemas.Post, params) #Ecto.Query<from p0 in Turbo.Ecto.Schemas.Post, where: like(p0.name, "%elixir%") or like(p0.body, "%elixir%"), order_by: [asc: p0.updated_at], limit: 5, offset: 0>