1.2 KiB
1.2 KiB
Data Layers
Data layers determine how resources are stored and retrieved. Examples of data layers:
- Postgres: For storing resources in PostgreSQL (via
AshPostgres) - ETS: For in-memory storage (
Ash.DataLayer.Ets) - Mnesia: For distributed storage (
Ash.DataLayer.Mnesia) - Embedded: For resources embedded in other resources (
data_layer: :embedded) (typically JSON under the hood) - Ash.DataLayer.Simple: For resources that aren't persisted at all. Leave off the data layer, as this is the default.
Specify a data layer when defining a resource:
defmodule MyApp.Post do
use Ash.Resource,
domain: MyApp.Blog,
data_layer: AshPostgres.DataLayer
postgres do
table "posts"
repo MyApp.Repo
end
# ... attributes, relationships, etc.
end
For embedded resources:
defmodule MyApp.Address do
use Ash.Resource,
data_layer: :embedded
attributes do
attribute :street, :string
attribute :city, :string
attribute :state, :string
attribute :zip, :string
end
end
Each data layer has its own configuration options and capabilities. Refer to the rules & documentation of the specific data layer package for more details.