Ecto Filters v0.2.1 Ecto.Filters View Source

Adds a macro add_filter and private function apply_filter/2 to transform request params into ecto query expressions.

Example

add_filter(:comment_body, fn value, query ->
  query
  |> join(:left, [p], c in assoc(p, :comments), as: :comments)
  |> where([comments: comments], ilike(comments.body, ^value))
end)

apply_filters(Post, %{"q" => %{"comment_body" => "some text"}}) |> MyRepo.all()
[%Post{title: "Ecto Filters"}, ...]

Link to this section Summary

Link to this section Functions

Link to this macro

add_filter(key, fun) View Source (macro)