Crudry v0.4.0 Crudry.Query View Source

Generates Ecto Queries.

All functions in this module return an Ecto.Query.

Link to this section Summary

Functions

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 limiting
  • offset: defaults to 0
  • sorting_order: defaults to :asc (only works if there is also a order_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])