ash v0.13.0 Ash.Api behaviour View Source
An Api allows you to interact with your resources, and holds non-resource-specific configuration.
Your Api can also house config that is not resource specific. Defining a resource won't do much for you. Once you have some resources defined, you include them in an Api like so:
defmodule MyApp.Api do
use Ash.Api
resources do
resource OneResource
resource SecondResource
end
Then you can interact through that Api with the actions that those resources expose.
For example: MyApp.Api.create(changeset)
, or MyApp.Api.read(query)
. Corresponding
actions must be defined in your resources in order to call them through the Api.
Link to this section Summary
Callbacks
Create a record.
Create a record. See create/2
for more information.
Destroy a record.
Destroy a record. See destroy/2
for more information.
Get a record by a primary key.
Get a record by a primary key. See get/3
for more.
Run a query on a resource.
Run an ash query. See read/2
for more.
Refetches a record by primary key.
Refetches a record by primary key. See reload/1
for more.
Side load on already fetched records.
Side load on already fetched records. See side_load/2
for more information.
Update a record.
Update a record. See update/2
for more information.
Link to this section Functions
Specs
resources(Ash.api()) :: [Ash.resource()]
Link to this section Callbacks
Specs
create(resource :: Ash.resource(), params :: Keyword.t()) :: {:ok, Ash.record()} | {:error, Ash.error()}
Create a record.
:upsert?
- If a conflict is found based on the primary key, the record is updated in the database (requires upsert support) The default value isfalse
.:side_load
- Side loads to include in the query, same as you would pass toAsh.Query.side_load/2
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Specs
create!(resource :: Ash.resource(), params :: Keyword.t()) :: Ash.record() | no_return()
Create a record. See create/2
for more information.
:upsert?
- If a conflict is found based on the primary key, the record is updated in the database (requires upsert support) The default value isfalse
.:side_load
- Side loads to include in the query, same as you would pass toAsh.Query.side_load/2
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Specs
destroy(record :: Ash.record(), params :: Keyword.t()) :: :ok | {:error, Ash.error()}
Destroy a record.
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Specs
destroy!(record :: Ash.record(), params :: Keyword.t()) :: :ok | no_return()
Destroy a record. See destroy/2
for more information.
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Specs
get(resource :: Ash.resource(), id_or_filter :: term(), params :: Keyword.t()) :: {:ok, Ash.record()} | {:error, Ash.error()}
Get a record by a primary key.
For a resource with a composite primary key, pass a keyword list, e.g
MyApi.get(MyResource, first_key: 1, second_key: 2)
:side_load
- Side loads to include in the query, same as you would pass toAsh.Query.side_load/2
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Specs
get!(resource :: Ash.resource(), id_or_filter :: term(), params :: Keyword.t()) :: Ash.record() | no_return()
Get a record by a primary key. See get/3
for more.
:side_load
- Side loads to include in the query, same as you would pass toAsh.Query.side_load/2
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Specs
read(Ash.query(), params :: Keyword.t()) :: {:ok, [Ash.resource()]} | {:error, Ash.error()}
Run a query on a resource.
For more information, on building a query, see Ash.Query
.
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Specs
read!(Ash.query(), params :: Keyword.t()) :: [Ash.resource()] | no_return()
Run an ash query. See read/2
for more.
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Specs
reload(record :: Ash.record()) :: {:ok, Ash.record()} | {:error, Ash.error()}
Refetches a record by primary key.
Specs
reload!(record :: Ash.record(), params :: Keyword.t()) :: Ash.record() | no_return()
Refetches a record by primary key. See reload/1
for more.
Specs
side_load(resource :: Ash.resource(), params :: Keyword.t() | Ash.query()) :: {:ok, [Ash.resource()]} | {:error, Ash.error()}
Side load on already fetched records.
Accepts a keyword list of side loads as they would be passed into Ash.Query.side_load/2
or an %Ash.Query{}
, in which case that query's side loads are used.
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Specs
side_load!(resource :: Ash.resource(), params :: Keyword.t() | Ash.query()) :: [Ash.resource()] | no_return()
Side load on already fetched records. See side_load/2
for more information.
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Specs
update(record :: Ash.record(), params :: Keyword.t()) :: {:ok, Ash.record()} | {:error, Ash.error()}
Update a record.
:side_load
- Side loads to include in the query, same as you would pass toAsh.Query.side_load/2
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Specs
update!(record :: Ash.record(), params :: Keyword.t()) :: Ash.record() | no_return()
Update a record. See update/2
for more information.
:side_load
- Side loads to include in the query, same as you would pass toAsh.Query.side_load/2
:verbose?
- Log engine operations (very verbose?) The default value isfalse
.:action
- The action to use, either an Action struct or the name of the action:authorize?
- If an actor is provided, authorization happens automatically. If not, this flag can be used to authorize with no user. The default value isfalse
.:actor
- If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access