View Source Ash.Resource.Calculation behaviour (ash v3.4.44)

The behaviour for defining a module calculation, and the struct for storing a defined calculation.

Summary

Types

opts()

@type opts() :: Keyword.t()

ref()

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

t()

@type t() :: %Ash.Resource.Calculation{
  allow_nil?: boolean(),
  arguments: [Ash.Resource.Calculation.Argument.t()],
  async?: boolean(),
  calculation: module() | {module(), keyword()},
  constraints: keyword(),
  description: nil | String.t(),
  filterable?: boolean(),
  load: keyword(),
  name: atom(),
  public?: boolean(),
  sensitive?: term(),
  sortable?: boolean(),
  type: nil | Ash.Type.t()
}

Callbacks

calculate(records, opts, context)

(optional)
@callback calculate(
  records :: [Ash.Resource.record()],
  opts :: opts(),
  context :: Ash.Resource.Calculation.Context.t()
) :: {:ok, [term()]} | [term()] | {:error, term()} | :unknown

describe(opts)

@callback describe(opts :: opts()) :: String.t()

expression(opts, context)

(optional)
@callback expression(opts :: opts(), context :: Ash.Resource.Calculation.Context.t()) ::
  any()

has_expression?()

@callback has_expression?() :: boolean()

init(opts)

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

load(query, opts, context)

@callback load(
  query :: Ash.Query.t(),
  opts :: opts(),
  context :: Ash.Resource.Calculation.Context.t()
) ::
  atom() | [atom()] | Keyword.t()

strict_loads?()

@callback strict_loads?() :: boolean()

Functions

expr_calc(expr)

schema()