Enhance Ecto with powerful queries.
The package can be installed by adding queryable
to your list of dependencies in mix.exs
:
def deps do
[
{:queryable, "~> 0.1.0"}
]
end
Documentation can be found at https://hexdocs.pm/queryable.
Extend an Ecto Schema by adding criteria:
defmodule Person do
use Queryable #instead of Ecto.Schema
schema "persons" do
field :name, :string
field :surname, :string
field :age, :integer
end
criteria(under: age, where: el.age < ^age)
criteria(ordered_by: field, order_by: ^field)
end
Then create an Ecto Query in one of the following modes:
Person.query(name: "John", under: 18)
Person.name("John") |> Person.under(18)
This query can then be passed to methods like Repo.all
.