Crudry v1.0.0 Crudry.Query View Source
Generates Ecto Queries.
All functions in this module return an Ecto.Query
.
Link to this section Summary
Functions
Filters the query
Applies some restrictions to the query
Searches for the search_term
in the given fields
Link to this section Functions
Link to this function
filter(initial_query, filters \\ []) View Source
Filters the query.
Examples
Crudry.Query.filter(MySchema, %{id: 5, name: "John"})
Crudry.Query.filter(MySchema, %{name: ["John", "Doe"]})
Link to this function
list(initial_query, opts \\ %{}) View Source
Applies some restrictions to the query.
Expects opts
to be a map containing some of these fields:
limit
: defaults to not limitingoffset
: defaults to0
sorting_order
: defaults to:asc
(only works if there is also aorder_by
specified)order_by
: defaults to not ordering
Examples
Crudry.Query.list(MySchema, %{limit: 10})
Crudry.Query.list(MySchema, %{limit: 10, offset: 3, sorting_order: :desc, order_by: :value})
Crudry.Query.list(MySchema, %{order_by: "value"})
Link to this function
search(initial_query, search_term, fields) View Source
Searches for the search_term
in the given fields
.
Examples
Crudry.Query.search(MySchema, "John", [:name])