Mix . install ( [
{ :ash , "~> 1.51.2" } ,
{ :kino , "~> 0.5.2" }
] )
defmodule MyApp.Tweet do
use Ash.Resource , data_layer: Ash.DataLayer.Ets
attributes do
uuid_primary_key ( :id )
attribute :body , :string do
allow_nil? ( false )
constraints ( max_length: 255 )
end
attribute ( :public , :boolean , allow_nil?: false , default: false )
create_timestamp ( :inserted_at )
update_timestamp ( :updated_at )
end
end
defmodule MyApp.User do
use Ash.Resource , data_layer: Ash.DataLayer.Ets
attributes do
attribute ( :email , :string ,
allow_nil?: false ,
constraints: [
match: ~r/ ^[\w .!#$%&’*+\- \/ =?\^ `{|}~]+@[a-zA-Z0-9-]+(\. [a-zA-Z0-9-]+)*$/ i
]
)
uuid_primary_key ( :id )
end
end
Set up the API and registry
defmodule MyApp.Api do
use Ash.Api
resources do
registry ( MyApp.Registry )
end
end
defmodule MyApp.Registry do
use Ash.Registry ,
extensions: [ Ash.Registry.ResourceValidations ]
entries do
entry ( MyApp.User )
entry ( MyApp.Tweet )
end
end
MyApp.User
|> Ash.Changeset . new ( % { email: "[email protected] " } )
|> MyApp.Api . create! ( )
users = MyApp.Api . read! ( MyApp.User )
Kino.DataTable . new ( users )