Ash.Resource.Preparation behaviour (ash v3.5.34)

View Source

The behaviour for an action-specific query preparation.

init/1 is defined automatically by use Ash.Resource.Preparation, but can be implemented if you want to validate/transform any options passed to the module.

The main function is prepare/3. It takes the query, any options that were provided when this preparation was configured on a resource, and the context, which currently only has the actor.

To access any query arguments from within a preparation, make sure you are using Ash.Query.get_argument/2 as the argument keys may be strings or atoms.

Summary

Types

ref()

@type ref() :: {module(), Keyword.t()} | module()

t()

@type t() :: %Ash.Resource.Preparation{
  on: [atom()],
  only_when_valid?: boolean(),
  preparation: ref(),
  where: [Ash.Resource.Validation.ref()]
}

Callbacks

init(opts)

@callback init(opts :: Keyword.t()) :: {:ok, Keyword.t()} | {:error, term()}

prepare(query_or_input, opts, context)

@callback prepare(
  query_or_input :: Ash.Query.t() | Ash.ActionInput.t(),
  opts :: Keyword.t(),
  context :: Ash.Resource.Preparation.Context.t()
) :: Ash.Query.t() | Ash.ActionInput.t()

supports(opts)

@callback supports(opts :: Keyword.t()) :: [module()]

Functions

prepare(module, query_or_input, opts, context)