https://github.com/danielefongo/queryable
Enhance Ecto with powerful queries.
https://github.com/danielefongo/queryable
criteria ecto elixir query
Last synced: about 1 month ago
JSON representation
Enhance Ecto with powerful queries.
- Host: GitHub
- URL: https://github.com/danielefongo/queryable
- Owner: danielefongo
- License: gpl-3.0
- Created: 2021-03-07T13:31:57.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-09T13:05:24.000Z (about 4 years ago)
- Last Synced: 2025-04-18T00:57:03.025Z (about 2 months ago)
- Topics: criteria, ecto, elixir, query
- Language: Elixir
- Homepage:
- Size: 48.8 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Queryable


[](https://hex.pm/packages/queryable)
Enhance Ecto with powerful queries.
## Installation
The package can be installed by adding `queryable` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:queryable, "~> 0.1.0"}
]
end
```## Documentation
Documentation can be found at [https://hexdocs.pm/queryable](https://hexdocs.pm/queryable).
## Usage
Extend an Ecto Schema by adding criteria:
``` elixir
defmodule Person do
use Queryable #instead of Ecto.Schemaschema "persons" do
field :name, :string
field :surname, :string
field :age, :integer
endcriteria(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:
``` elixir
Person.query(name: "John", under: 18)
`````` elixir
Person.name("John") |> Person.under(18)
```This query can then be passed to methods like `Repo.all`.