ash v1.6.5 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.
Load fields or relationships on already fetched records.
Load fields or relationships on already fetched records. See load/2
for more information.
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.
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
.: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
.: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)
:load
- Fields or relationships to load in the query. SeeAsh.Query.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.
:load
- Fields or relationships to load in the query. SeeAsh.Query.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
load( record_or_records :: Ash.record() | [Ash.record()], params :: Keyword.t() | Ash.query() ) :: {:ok, Ash.record() | [Ash.record()]} | {:error, Ash.error()}
Load fields or relationships on already fetched records.
Accepts a list of non-loaded fields and loads them on the provided records or a query, in
which case the loaded fields of the query are used. Relationship loads can be nested, for
example: MyApi.load(record, [posts: [:comments]])
. See Ash.Query.side_load/2
for more
information on specifically loading relationships.
: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
load!( record_or_records :: Ash.record() | [Ash.record()], params :: Keyword.t() | Ash.query() ) :: Ash.record() | [Ash.record()] | no_return()
Load fields or relationships on already fetched records. See 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
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
update(record :: Ash.record(), params :: Keyword.t()) :: {:ok, Ash.record()} | {:error, Ash.error()}
Update 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
update!(record :: Ash.record(), params :: Keyword.t()) :: Ash.record() | no_return()
Update a record. See update/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