Ash.Expr (ash v3.37.6)

Copy Markdown View Source

Tools to build Ash expressions

Summary

Functions

A template helper for using actor values in filter templates

A template helper for using action arguments in filter templates

A template helper for referring to the most recent atomic expression applied to an update field

Creates an expression calculation for use in sort and distinct statements.

A template helper for creating a reference

A template helper for using query context in filter templates

Determines the type of an expression, as {:ok, {type, constraints}}, or :error if it can't be determined.

Determines the type of an expression like determine_type/1, along with the type of every operand it was resolved from, and theirs, and so on.

Determines the types for a given operator or function module and its arguments.

Determines the types for an operator or function module and its arguments, like determine_types/4, given the types of the arguments.

Evaluate an expression. This function only works if you have no references, or if you provide the record option.

Evaluate an expression. See eval/2 for more.

Creates an expression. See the Expressions guide for more.

Returns true if the value is or contains an expression

A template helper for creating a parent reference

A template helper for creating a reference

A template helper for creating a reference to a related path

Whether or not a given template contains an actor reference

A template helper for using the tenant in filter templates

Prepares a filter for comparison

Types

t()

@type t() :: any()

Functions

actor(value)

A template helper for using actor values in filter templates

arg(name)

A template helper for using action arguments in filter templates

atomic_ref(expr)

A template helper for referring to the most recent atomic expression applied to an update field

calc(expression, opts \\ [])

(macro)
@spec calc(Macro.t(), opts :: Keyword.t()) :: t()

Creates an expression calculation for use in sort and distinct statements.

Examples

Ash.Query.sort(query, [
  {calc(string_upcase(name), :asc},
  {calc(count_nils([field1, field2]), type: :integer), :desc})
])

can_return_nil?(pred)

combinations(name)

A template helper for creating a reference

context(name)

A template helper for using query context in filter templates

An atom will get the value for a key, and a list will be accessed via get_in.

determine_type(value)

Determines the type of an expression, as {:ok, {type, constraints}}, or :error if it can't be determined.

The type of an operator or function call is resolved from the types of its operands, so this walks the whole expression below it.

determine_type_tree(value)

@spec determine_type_tree(term()) :: Ash.Expr.TypeTree.t()

Determines the type of an expression like determine_type/1, along with the type of every operand it was resolved from, and theirs, and so on.

Takes time linear in the size of the expression. See determine_types_with_operand_types/4 for what it is for.

determine_types(mod, args, returns \\ nil, nested? \\ false)

Determines the types for a given operator or function module and its arguments.

Given an operator or function module (e.g. Ash.Query.Operator.In), resolves the concrete types of the arguments based on the module's declared type signatures and any registered operator overloads. Returns {resolved_types, return_type} where resolved_types is a list of {type, constraints} tuples (or nil for unresolvable arguments) and return_type is the resolved return type.

This is the primary type resolution mechanism used by data layer expression compilers. It performs actual type validation including coercion checks, unlike Ash.Type.determine_types/2 which only resolves vague types (:same/:any).

determine_types_with_operand_types(mod, values, operand_types, returns \\ nil)

@spec determine_types_with_operand_types(
  module(),
  [term()],
  [{:ok, {Ash.Type.t(), Keyword.t()}} | :error],
  term()
) :: {[{Ash.Type.t(), Keyword.t()} | nil], {Ash.Type.t(), Keyword.t()} | nil}

Determines the types for an operator or function module and its arguments, like determine_types/4, given the types of the arguments.

operand_types has one entry per argument, as determine_type/1 returns it for that argument: {:ok, {type, constraints}} or :error. determine_types/4 works these out itself, by walking each argument's whole subtree. A caller that types an expression top down, calling this at every node (as a data layer compiling an expression does), would repeat that walk for each level above a node and so take time proportional to the size of the tree times its depth. Instead, it can type the tree once with determine_type_tree/1, and at each node pass the types of its operands from there.

eval(expression, opts \\ [])

Evaluate an expression. This function only works if you have no references, or if you provide the record option.

eval!(expression, opts \\ [])

Evaluate an expression. See eval/2 for more.

expr(body)

(macro)
@spec expr(Macro.t()) :: t()

Creates an expression. See the Expressions guide for more.

expr?(value)

@spec expr?(term()) :: boolean()

Returns true if the value is or contains an expression

or_where(left, right)

(macro)
@spec or_where(Macro.t(), Macro.t()) :: t()

parent(expr)

A template helper for creating a parent reference

ref(name)

A template helper for creating a reference

ref(path, name)

A template helper for creating a reference to a related path

template_references?(list, pred)

Whether or not a given template contains an actor reference

template_references_argument?(template)

template_references_context?(template)

tenant()

A template helper for using the tenant in filter templates

to_sat_expression(resource, expression)

Prepares a filter for comparison

where(left, right)

(macro)
@spec where(Macro.t(), Macro.t()) :: t()