#
View Source Ash.Resource.Preparation.Builtins (ash v2.4.22)

Builtin query preparations

# Link to this section Summary

## Functions

build(options)

Passes the given keyword list to `Ash.Query.build/2` with the query being prepared.

set_context(context)

Merges the given query context.

# Link to this section Functions

Link to this function

# build(options)

View Source

    @spec build(Keyword.t()) :: Ash.Resource.Preparation.ref()

Passes the given keyword list to `Ash.Query.build/2` with the query being prepared.

This allows declaring simple query modifications in-line.

##

options

Options

- `:filter` (`term/0`) - A filter keyword, expression or %Ash.Filter{}

- `:sort` (`term/0`) - A sort list or keyword

- `:limit` (`integer/0`) - A limit to apply

- `:offset` (`integer/0`) - An offset to apply

- `:load` (`term/0`) - A load statement to add to the query

- `:aggregate` (`term/0`) - A custom aggregate to add to the query. Can be `{name, type, relationship}` or `{name, type, relationship, build_opts}`

- `:calculate` (`term/0`) - A custom calculation to add to the query. Can be `{name, module_and_opts}` or `{name, module_and_opts, context}`

- `:distinct` (list of `atom/0`) - A distinct clause to add to the query

- `:context` (`map/0`) - A map to merge into the query context

##

examples

Examples

    prepare build(sort: [song_rank: :desc], limit: 10)
    prepare build(load: [:friends])

Link to this function

# set_context(context)

View Source

    @spec set_context(context :: map() | mfa()) :: Ash.Resource.Preparation.ref()

Merges the given query context.

If an MFA is provided, it will be called with the changeset. The MFA should return `{:ok, context_to_be_merged}` or `{:error, term}`

##

examples

Examples

    change set_context(%{something_used_internally: true})
    change set_context({MyApp.Context, :set_context, []})