ash_postgres/lib/repo.ex
2020-07-07 20:01:01 -04:00

36 lines
1 KiB
Elixir

defmodule AshPostgres.Repo do
@moduledoc """
Resources that use the `AshPostgres` data layer use a `Repo` to access the database.
This repo is a slightly modified version of an `Ecto.Repo`.
You can use `Ecto.Repo`'s `init/2` to configure your repo like normal, but
instead of returning `{:ok, config}`, use `super(config)` to pass the
configuration to the `AshPostgres.Repo` implementation.
"""
@doc "Use this to inform the data layer about what extensions are installed"
@callback installed_extensions() :: [String.t()]
defmacro __using__(opts) do
quote bind_quoted: [opts: opts] do
otp_app = opts[:otp_app] || raise("Must configure OTP app")
use Ecto.Repo,
adapter: Ecto.Adapters.Postgres,
otp_app: otp_app
def installed_extensions do
[]
end
def init(_, config) do
new_config = Keyword.put(config, :installed_extensions, installed_extensions())
{:ok, new_config}
end
defoverridable installed_extensions: 0
end
end
end