Ash.DataLayer behaviour (ash v1.37.2) View Source

The interface for being an ash data layer.

This is a large behaviour, and this capability is not complete, but the idea is to have a large amount of optional callbacks, and use the can?/2 callback to ensure that the engine only ever tries to interact with the data layer in ways that it supports.

Link to this section Summary

Link to this section Types

Specs

data_layer_query() :: struct()

Specs

feature() ::
  :transact
  | :multitenant
  | {:lateral_join, Ash.Resource.t()}
  | {:join, Ash.Resource.t()}
  | {:aggregate, Ash.Query.Aggregate.kind()}
  | {:query_aggregate, Ash.Query.Aggregate.kind()}
  | :aggregate_filter
  | :aggregate_sort
  | :boolean_filter
  | :async_engine
  | :create
  | :read
  | :update
  | :destroy
  | :limit
  | :offset
  | :transact
  | :filter
  | {:filter_expr, struct()}
  | :sort
  | {:sort, Ash.Type.t()}
  | :upsert
  | :composite_primary_key

Specs

t() :: module()

Link to this section Functions

Link to this function

add_aggregate(query, aggregate, resource)

View Source

Specs

add_aggregate(data_layer_query(), Ash.Query.Aggregate.t(), Ash.Resource.t()) ::
  {:ok, data_layer_query()} | {:error, term()}

Specs

can?(feature(), Ash.Resource.t()) :: boolean()
Link to this function

create(resource, changeset)

View Source

Specs

create(Ash.Resource.t(), Ash.Changeset.t()) ::
  {:ok, Ash.Resource.record()} | {:error, term()}

Specs

data_layer(Ash.Resource.t()) :: t()

The data layer of the resource, or nil if it does not have one

Link to this function

data_layer_can?(resource, feature)

View Source

Specs

data_layer_can?(Ash.Resource.t(), feature()) :: boolean()

Whether or not the data layer supports a specific feature

Link to this function

data_layer_functions(resource)

View Source

Specs

data_layer_functions(Ash.Resource.t()) :: map()

Custom functions supported by the data layer of the resource

Link to this function

destroy(resource, changeset)

View Source

Specs

destroy(Ash.Resource.t(), Ash.Changeset.t()) :: :ok | {:error, term()}
Link to this function

filter(query, filter, resource)

View Source

Specs

filter(data_layer_query(), Ash.Filter.t(), Ash.Resource.t()) ::
  {:ok, data_layer_query()} | {:error, term()}
Link to this function

in_transaction?(resource)

View Source
Link to this function

limit(query, limit, resource)

View Source

Specs

limit(data_layer_query(), limit :: non_neg_integer(), Ash.Resource.t()) ::
  {:ok, data_layer_query()} | {:error, term()}
Link to this function

offset(query, offset, resource)

View Source

Specs

offset(data_layer_query(), offset :: non_neg_integer(), Ash.Resource.t()) ::
  {:ok, data_layer_query()} | {:error, term()}
Link to this function

resource_to_query(resource, api)

View Source

Specs

resource_to_query(Ash.Resource.t(), Ash.Api.t()) :: data_layer_query()
Link to this function

rollback(resource, term)

View Source

Specs

rollback(Ash.Resource.t(), term()) :: no_return()

Rolls back the current transaction

Link to this function

run_aggregate_query(query, aggregates, resource)

View Source

Specs

run_aggregate_query(
  data_layer_query(),
  [Ash.Query.Aggregate.t()],
  Ash.Resource.t()
) :: {:ok, map()} | {:error, term()}
Link to this function

run_aggregate_query_with_lateral_join(query, aggregates, root_data, source_resource, destination_resource, source, destination)

View Source
Link to this function

run_query(query, central_resource)

View Source

Specs

run_query(data_layer_query(), central_resource :: Ash.Resource.t()) ::
  {:ok, [Ash.Resource.record()]} | {:error, term()}
Link to this function

run_query_with_lateral_join(query, root_data, source_resource, destination_resource, source, destination)

View Source
Link to this function

set_context(resource, query, map)

View Source

Specs

set_context(Ash.Resource.t(), data_layer_query(), map()) ::
  {:ok, data_layer_query()} | {:error, term()}
Link to this function

set_tenant(resource, query, term)

View Source

Specs

set_tenant(Ash.Resource.t(), data_layer_query(), term()) ::
  {:ok, data_layer_query()} | {:error, term()}
Link to this function

sort(query, sort, resource)

View Source

Specs

sort(data_layer_query(), Ash.Sort.t(), Ash.Resource.t()) ::
  {:ok, data_layer_query()} | {:error, term()}

Specs

source(Ash.Resource.t()) :: String.t()
Link to this function

transact(resource, func)

View Source
Link to this function

transaction(resource, func)

View Source

Specs

transaction(Ash.Resource.t(), (() -> term())) :: term()

Wraps the execution of the function in a transaction with the resource's data_layer

Link to this function

update(resource, changeset)

View Source

Specs

update(Ash.Resource.t(), Ash.Changeset.t()) ::
  {:ok, Ash.Resource.record()} | {:error, term()}
Link to this function

upsert(resource, changeset)

View Source

Specs

upsert(Ash.Resource.t(), Ash.Changeset.t()) ::
  {:ok, Ash.Resource.record()} | {:error, term()}

Link to this section Callbacks

Link to this callback

add_aggregate(data_layer_query, arg2, arg3)

View Source (optional)

Specs

add_aggregate(data_layer_query(), Ash.Query.Aggregate.t(), Ash.Resource.t()) ::
  {:ok, data_layer_query()} | {:error, term()}

Specs

can?(Ash.Resource.t(), feature()) :: boolean()
Link to this callback

create(arg1, arg2)

View Source (optional)

Specs

create(Ash.Resource.t(), Ash.Changeset.t()) ::
  {:ok, Ash.Resource.t()} | {:error, term()}
Link to this callback

destroy(arg1, arg2)

View Source (optional)

Specs

destroy(Ash.Resource.t(), Ash.Changeset.t()) :: :ok | {:error, term()}

Specs

equal?(t()) :: boolean()
Link to this callback

filter(data_layer_query, arg2, resource)

View Source (optional)

Specs

filter(data_layer_query(), Ash.Filter.t(), resource :: Ash.Resource.t()) ::
  {:ok, data_layer_query()} | {:error, term()}
Link to this callback

functions(arg1)

View Source (optional)

Specs

functions(Ash.Resource.t()) :: [module()]
Link to this callback

in_transaction?(arg1)

View Source (optional)

Specs

in_transaction?(Ash.Resource.t()) :: boolean()
Link to this callback

limit(data_layer_query, limit, resource)

View Source (optional)

Specs

limit(
  data_layer_query(),
  limit :: non_neg_integer(),
  resource :: Ash.Resource.t()
) :: {:ok, data_layer_query()} | {:error, term()}
Link to this callback

offset(data_layer_query, offset, resource)

View Source (optional)

Specs

offset(
  data_layer_query(),
  offset :: non_neg_integer(),
  resource :: Ash.Resource.t()
) :: {:ok, data_layer_query()} | {:error, term()}
Link to this callback

operators(arg1)

View Source (optional)

Specs

operators(Ash.Resource.t()) :: [module()]
Link to this callback

resource_to_query(arg1, arg2)

View Source (optional)

Specs

resource_to_query(Ash.Resource.t(), Ash.Api.t()) :: data_layer_query()
Link to this callback

rollback(arg1, term)

View Source (optional)

Specs

rollback(Ash.Resource.t(), term()) :: no_return()
Link to this callback

run_aggregate_query(data_layer_query, list, arg3)

View Source (optional)

Specs

run_aggregate_query(
  data_layer_query(),
  [Ash.Query.Aggregate.t()],
  Ash.Resource.t()
) :: {:ok, map()} | {:error, term()}
Link to this callback

run_aggregate_query_with_lateral_join(data_layer_query, list, list, source_resource, destination_resource, source, destination)

View Source (optional)

Specs

run_aggregate_query_with_lateral_join(
  data_layer_query(),
  [Ash.Query.Aggregate.t()],
  [Ash.Resource.record()],
  source_resource :: Ash.Resource.t(),
  destination_resource :: Ash.Resource.t(),
  source :: atom(),
  destination :: atom()
) :: {:ok, [Ash.Resource.t()]} | {:error, term()}
Link to this callback

run_query(data_layer_query, arg2)

View Source (optional)

Specs

run_query(data_layer_query(), Ash.Resource.t()) ::
  {:ok, [Ash.Resource.t()]} | {:error, term()}
Link to this callback

run_query_with_lateral_join(data_layer_query, list, source_resource, destination_resource, source, destination)

View Source (optional)

Specs

run_query_with_lateral_join(
  data_layer_query(),
  [Ash.Resource.record()],
  source_resource :: Ash.Resource.t(),
  destination_resource :: Ash.Resource.t(),
  source :: atom(),
  destination :: atom()
) :: {:ok, [Ash.Resource.t()]} | {:error, term()}
Link to this callback

set_context(arg1, data_layer_query, map)

View Source (optional)

Specs

set_context(Ash.Resource.t(), data_layer_query(), map()) ::
  {:ok, data_layer_query()} | {:error, term()}
Link to this callback

set_tenant(arg1, data_layer_query, term)

View Source (optional)

Specs

set_tenant(Ash.Resource.t(), data_layer_query(), term()) ::
  {:ok, data_layer_query()} | {:error, term()}
Link to this callback

sort(data_layer_query, arg2, resource)

View Source (optional)

Specs

sort(data_layer_query(), Ash.Sort.t(), resource :: Ash.Resource.t()) ::
  {:ok, data_layer_query()} | {:error, term()}

Specs

source(Ash.Resource.t()) :: String.t()
Link to this callback

transaction(arg1, function)

View Source (optional)

Specs

transaction(Ash.Resource.t(), (() -> term())) ::
  {:ok, term()} | {:error, term()}
Link to this callback

transform_query(arg1)

View Source (optional)

Specs

transform_query(Ash.Query.t()) :: Ash.Query.t()
Link to this callback

update(arg1, arg2)

View Source (optional)

Specs

update(Ash.Resource.t(), Ash.Changeset.t()) ::
  {:ok, Ash.Resource.t()} | {:error, term()}
Link to this callback

upsert(arg1, arg2)

View Source (optional)

Specs

upsert(Ash.Resource.t(), Ash.Changeset.t()) ::
  {:ok, Ash.Resource.t()} | {:error, term()}