EctoTurbo (EctoTurbo v1.0.0)

View Source

A rich ecto component, including search sort and paginate.

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> 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.

Returns processed queryable.

Functions

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

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

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: []
}

turboq(queryable, params)

@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>