ash v1.13.0 Ash.Query View Source

Utilties around constructing/manipulating ash queries.

Ash queries are used for read actions and side loads, and ultimately map to queries to a resource's data layer.

Link to this section Summary

Link to this section Types

Specs

t() :: %Ash.Query{
  aggregates: term(),
  api: term(),
  calculations: term(),
  context: term(),
  data_layer_query: term(),
  errors: term(),
  filter: term(),
  limit: term(),
  offset: term(),
  resource: term(),
  side_load: term(),
  sort: term(),
  valid?: term()
}

Link to this section Functions

Link to this function

aggregate(query, name, type, relationship, agg_query \\ nil)

View Source

Specs

aggregate(
  t() | Ash.resource(),
  atom(),
  Ash.aggregate_kind(),
  atom() | [atom()],
  Ash.query() | nil
) :: t()

Adds an aggregation to the query.

Aggregations are made available on the aggregates field of the records returned

The only aggregate available currently is a count aggregate. They filter option accepts either a filter or a keyword list of options to supply to build a limiting query for that aggregate. However, currently only filters are accepted.

Link to this function

build(resource, api \\ nil, keyword)

View Source

Specs

build(Ash.resource(), Ash.api() | nil, Keyword.t()) :: t()
Link to this function

calculate(query, name, module_and_opts, context \\ %{})

View Source

Adds a calculation to the query.

Calculations are made available on the calculations field of the records returned

The module_and_opts argument accepts either a module or a {module, opts}. For more information on what that module should look like, see Ash.Calculation.

More features for calculations, like passing anonymous functions, will be supported in the future.

Link to this function

do_validate_side_load(resource, query, path)

View Source

Specs

filter(t() | Ash.resource(), nil | false | Ash.filter() | Keyword.t()) :: t()

Specs

limit(t() | Ash.resource(), nil | integer()) :: t()

Limit the results returned from the query

Specs

load(t(), atom() | [atom()] | Keyword.t()) :: t()
Link to this function

new(resource, api \\ nil)

View Source

Create a new query.

Specs

offset(t() | Ash.resource(), nil | integer()) :: t()

Skip the first n records

Link to this function

put_context(query, key, value)

View Source

Specs

put_context(t(), atom(), term()) :: t()

Set the query's api, and any side loaded query's api

Specs

set_context(t(), map()) :: t()

Specs

sort(t() | Ash.resource(), Ash.sort()) :: t()

Specs

unset(Ash.resource() | t(), atom() | [atom()]) :: t()
Link to this function

validate_side_load(resource, side_loads, path \\ [])

View Source