Simpler would be this:
defmodule MyApp.Resource do
defmacro __using__(opts) do
{data_layer, extension_to_add} =
if App.Config.use_sqlite?() do
{AshSqlite.DataLayer, AshPostgres.DataLayer}
else
{AshPostgres.DataLayer, AshSqlite.DataLayer}
end
{table, opts} = Keyword.pop(opts, :table)
opts =
opts
|> Keyword.put_new(:data_layer, data_layer)
|> Keyword.update(:extensions, [extension_to_add], &[extension_to_add | &1])
quote do
use Ash.Resource, unquote(opts)
postgres do
table unquote(table)
repo YourRepo
end
sqlite do
table unquote(table)
repo YourRepo
end
end
end
end
You can use the postgres and sqlite extensions multiple times, and can add it as an extension without making it the data layer so that when you have special sqlite or postgres specific things in a resource, you can just do postgres do ... and not include table.






















