View Source EctoShorts.CommonFilters (ecto_shorts v1.1.2)
This modules main purpose is to house a collection of common schema filters and functionality to be included in params -> filters
Common filters available include
preload
- Preloads fields onto the query resultsstart_date
- Query for items inserted after this dateend_date
- Query for items inserted before this datebefore
- Get items with ID's before this valueafter
- Get items with ID's after this valueids
- Get items with a list of idsfirst
- Gets the first n itemslast
- Gets the last n itemslimit
- Gets the first n itemsoffset
- Offsets limit by n itemsorder_by
- orders the results in desc or asc ordersearch
- Warning: This requires schemas using this to have a&by_search(query, val)
function
You are also able to filter on any natural field of a model, as well as use
- gte/gt
- lte/lt
- like/ilike
- is_nil/not(is_nil)
CommonFilters.convert_params_to_filter(User, %{name: %{ilike: "steve"}})
CommonFilters.convert_params_to_filter(User, %{name: %{age: %{gte: 18, lte: 30}}})
CommonFilters.convert_params_to_filter(User, %{name: %{is_banned: %{!=: nil}}})
CommonFilters.convert_params_to_filter(User, %{name: %{is_banned: %{==: nil}}})
CommonFilters.convert_params_to_filter(User, %{name: %{balance: %{!=: 0}}})
CommonFilters.convert_params_to_filter(User, %{name: "Billy"})
Link to this section Summary
Functions
Converts filter params into a query
Link to this section Functions
Specs
convert_params_to_filter( queryable :: Ecto.Query.t(), params :: Keyword.t() | map() ) :: Ecto.Query.t()
Converts filter params into a query