PhoenixApiToolkit.Ecto.DynamicFilters.standard_filters

You're seeing just the macro standard_filters, go back to PhoenixApiToolkit.Ecto.DynamicFilters module for more information.
Link to this macro

standard_filters(query, filter, default_binding, filter_definitions)

View Source (macro)

Specs

standard_filters(Ecto.Query.t(), filter(), atom(), filter_definitions()) ::
  any()

Same as standard_filters/5 but does not support dynamically resolving named bindings.

Link to this macro

standard_filters(query, filter, default_binding, filter_definitions, resolve_binding)

View Source (macro)

Specs

standard_filters(
  Ecto.Query.t(),
  filter(),
  atom(),
  filter_definitions(),
  (Ecto.Query.t(), atom() -> Ecto.Query.t())
) :: any()

Applies standard filters to the query. Standard filters include filters for equal_to matches, set membership, smaller/greater than comparisons, ordering and pagination.

See the module docs Elixir.PhoenixApiToolkit.Ecto.DynamicFilters for details and examples.

Mandatory parameters:

  • query: the Ecto query that is narrowed down
  • filter: the current filter that is being applied to query
  • default_binding: the named binding of the Ecto model that generic queries are applied to, unless specified otherwise
  • filter_definitions: keyword list of filter types and the filter definitions for which they should be generated

Optional parameters:

  • resolve_binding: a function that can be passed in to dynamically join the query to resolve named bindings requested in filters

The options supported by the filter_definitions parameter are:

  • atom_keys: supports filter keys as atoms, e.g. %{username: "Dave"}
  • string_keys: supports filter keys as strings, e.g. %{"username" => "Dave"}. Note that order_by VALUES must always be atoms: %{"order_by" => :username} will work but %{order_by: "username"} will not.
  • limit: enables limit filter
  • offset: enables offset filter
  • order_by: enables order_by filter
  • order_by_aliases: set an alias for a non-default-binding-field, e.g. {:role_name, {:role, :name}} which enables order_by: [desc: :role_name]
  • equal_to: field must be equal to filter.
  • equal_to_any: field must be equal to any value of filter, e.g. user.id in [1, 2, 3]. Filter names can be the same as equal_to filters.
  • smaller_than: field must be smaller than filter value, e.g. user.score < value
  • greater_than_or_equal_to: field must be greater than or equal to filter value, e.g. user.score >= value
  • string_starts_with: string field must start with case-insensitive string prefix, e.g. user.name starts with "dav"
  • string_contains: string field must contain case-insensitive string, e.g. user.name contains "av"
  • list_contains: array field must contain filter value, e.g. "admin" in user.roles (equivalent to set membership)
  • list_contains_any: array field must contain any filter value, e.g. user.roles contains any of ["admin", "creator"] (equivalent to set intersection). Filter names can be the same as list_contains filters.
  • list_contains_all: array field must contain all filter values, e.g. user.roles contains all of ["admin", "creator"] (equivalent to subset). Filter names can be the same as list_contains filters.