trubo_ecto v0.1.2 Trubo.Ecto
Elixir Search compoment, support single table search, sort and paginate.
Link to this section Summary
Functions
Gets paginate info
Returns Paginate result
Returns Paginate queryable
Returns searching result
Returns searching queryable
Returns sorting result
Returns sorting queryable
Returns a result and pageinate info
Returns processed queryable
Link to this section Functions
Link to this function
get_paginate(queryable, params, opts \\ [])
Gets paginate info.
Example
iex> params = %{"per_page" => 5, "page" => 2}
iex> Trubo.Ecto.get_paginate(Trubo.Ecto.Product, params)
%{per_page: 5, current_page: 2, next_page: nil, prev_page: nil, total_count: 0, total_pages: 0}
Link to this function
paginate(queryable, params, opts \\ [])
paginate(Ecto.Query.t(), Map.t(), Keyword.t()) :: Map.t()
Returns Paginate result.
Example
iex> params = %{"per_page" => 5, "page" => 2}
iex> Trubo.Ecto.paginate(Trubo.Ecto.Product, params)
%{dates: [], paginate: %{current_page: 2, next_page: nil, per_page: 5, prev_page: nil, total_count: 0, total_pages: 0}}
Link to this function
paginateq(queryable, params)
paginateq(Ecto.Query.t(), Map.t()) :: Ecto.Query.t()
Returns Paginate queryable.
Example
iex> params = %{"per_page" => 5, "page" => 2}
iex> Trubo.Ecto.paginateq(Trubo.Ecto.Product, params)
#Ecto.Query<from p in Trubo.Ecto.Product, limit: ^5, offset: ^5>
Link to this function
search(queryable, params, opts \\ [])
search(Ecto.Query.t(), Map.t(), Keyword.t()) :: any()
Returns searching result.
Example
iex> params = %{"q" => %{"name_like" => "q"}}
iex> Trubo.Ecto.search(Trubo.Ecto.Product, params)
[]
Link to this function
searchq(queryable, params)
Returns searching queryable.
Example
iex> Trubo.Ecto.searchq(Trubo.Ecto.Product, %{"q" => %{"name_like" => "q"}})
#Ecto.Query<from p in Trubo.Ecto.Product, where: like(p.name, ^"%q%")>
Link to this function
sort(queryable, params, opts \\ [])
sort(Ecto.Query.t(), Map.t(), Keyword.t()) :: any()
Returns sorting result.
Example
iex> params = %{"s" => "updated_at+desc"}
iex> Trubo.Ecto.sort(Trubo.Ecto.Product, params)
[]
Returns sorting queryable.
Example
iex> params = %{"s" => "updated_at+desc"}
iex> Trubo.Ecto.sortq(Trubo.Ecto.Product, params)
#Ecto.Query<from p in Trubo.Ecto.Product, order_by: [desc: p.updated_at]>
Link to this function
trubo(queryable, params, opts \\ [])
trubo(Ecto.Query.t(), Map.t(), Keyword.t()) :: Map.t()
Returns a result and pageinate info.
Example
iex> params = %{"q" => %{"name_like" => "q"}, "s" => "updated_at+asc", "per_page" => 5, "page" => 1}
iex> Trubo.Ecto.trubo(Trubo.Ecto.Product, 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_like" => "name", "body_like" => "body"}, "s" => "updated_at+asc", "per_page" => 5, "page" => 1}
iex> Trubo.Ecto.truboq(Trubo.Ecto.Product, params)
#Ecto.Query<from p in Trubo.Ecto.Product, where: like(p.body, ^"%body%"), where: like(p.name, ^"%name%"), order_by: [asc: p.updated_at], limit: ^5, offset: ^0>