Chris
Chris
AEAsh Elixir
Created by Chris on 10/12/2023 in #support
read action returning a boolean
defmodule Blah.Blah.LiveFeatureFlags do
use Ash.Resource, data_layer: Ash.DataLayer.Ets
require Ash.Query

actions do
defaults([:create, :read, :destroy])
end

attributes do
uuid_primary_key(:id)
attribute(:name, :string, allow_nil?: false)
attribute(:is_enabled, :boolean, allow_nil?: false)
end

code_interface do
define_for(Blah.Blah)
define(:create)
define(:read)
define(:destroy)
end

def is_enabled?(name) do
__MODULE__
|> Ash.Query.for_read(:read)
|> Ash.Query.filter(name == ^name)
|> Blah.Blah.read!()
|> case do
[%{is_enabled: is_enabled} | _] -> is_enabled
_ -> true
end
end
end
defmodule Blah.Blah.LiveFeatureFlags do
use Ash.Resource, data_layer: Ash.DataLayer.Ets
require Ash.Query

actions do
defaults([:create, :read, :destroy])
end

attributes do
uuid_primary_key(:id)
attribute(:name, :string, allow_nil?: false)
attribute(:is_enabled, :boolean, allow_nil?: false)
end

code_interface do
define_for(Blah.Blah)
define(:create)
define(:read)
define(:destroy)
end

def is_enabled?(name) do
__MODULE__
|> Ash.Query.for_read(:read)
|> Ash.Query.filter(name == ^name)
|> Blah.Blah.read!()
|> case do
[%{is_enabled: is_enabled} | _] -> is_enabled
_ -> true
end
end
end
I wasn't able to figure out how to use a generic action but this does the job
4 replies
AEAsh Elixir
Created by Chris on 10/12/2023 in #support
read action returning a boolean
thanks, having a go now
4 replies