8000 GitHub - aeturnumfluctus/turbo_ecto: A rich ecto component, including search sort and paginate.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

aeturnumfluctus/turbo_ecto

 
 

Repository files navigation

Turbo Ecto

Build Status

Turbo is a very rich ecto component,including search sort and paginate. Inspiration by ruby ransack and learn from rummage_ecto

Phoenix support turbo_html, check this repos.

Table of contents

Getting started

  • The package can be installed by adding turbo_ecto to your list of dependencies in mix.exs:
def deps do
  [
    {:turbo_ecto, "~> 0.1.7"}
  ]
end
  • Add the Repo of your app and the desired per_page to the turbo_ecto configuration in config.exs:
config :turbo_ecto, Turbo.Ecto,
  repo: MyApp.Repo,
  per_page: 10

Examples

  • 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
  iex> params = %{"q" => %{"product_category_name_and_product_name_or_name_like" => "elixir", "s" => "inserted_at+asc"}}

  iex> Turbo.Ecto.turboq(Turbo.Ecto.Variant, params)
  Ecto.Query<from v in subquery(from v in subquery(from v in subquery(from v in Turbo.Ecto.Variant),
    join: p in assoc(v, :product),
    join: c in assoc(p, :category),
    where: like(c.name, ^"%elixir%")),
    join: p in assoc(v, :product),
    where: like(p.name, ^"%elixir%")),
    or_where: like(v.name, ^"%elixir%"),
    limit: ^10, offset: ^0,
    order_by: [asc: v.inserted_at]>

  iex> Turbo.Ecto.turbo(Turbo.Ecto.Variant, params)
  %{
    datas: [Variant],
    paginate: %{
      current_page: 10,
      next_page: 11,
      per_page: 5,
      prev_page: 9,
      total_count: 100,
      total_pages: 20
    }
  }

Also supports:

  • Use Turbo.Ecto.search only returns search result or use Turbo.Ecto.searchq returns search queryable;
  • Use Turbo.Ecto.sort only returns sort result or use Turbo.Ecto.sortq returns sort queryable;
  • Use Turbo.Ecto.paginate returns pagiante result or use Turbo.Ecto.paginateq returns paginate queryable.

More example pls move: docs

Search Matchers

List of all possible predicates

Predicate Description Finish Note
*_eq equal Y (SQL: col = 'value')
*_not_eq not equal N (SQL: col != 'value')
*_lt less than Y (SQL: col < 1024)
*_lteq less than or equal Y (SQL: col <= 1024)
*_gt greater than Y (SQL: col > 1024)
*_gteq greater than or equal Y greater than or equal. (SQL: col >= 1024)
*_present not null and not empty N Only compatible with string columns. Example: q[name_present]=1 (SQL: col is not null AND col != '')
*_is_null is null true or false N (SQL: col is null or col is not null)
*_in match any values in array N e.g. q[name_in][]=Alice&q[name_in][]=Bob (SQL: name in ('Alice', 'Bob'))
*_like Contains value Y (SQL: col LIKE '%value%')
*_ilike Contains any of Y (SQL: col ILIKE '%value%')
*_is_true is true or false N (SQL: col is true or col is false)
*_between begin < between < end N e.g. q[price_between][]=100&q[price_between][]=200 (SQL: 100 <= price <= 200)

Credits

About

A rich ecto component, including search sort and paginate.

Resources

License

Stars

Watchers

Forks

Releases

No releases published< 3230 /div>

Packages

No packages published

Languages

  • Elixir 99.8%
  • Shell 0.2%
0