# SPDX-FileCopyrightText: 2023 ash_sqlite contributors # # SPDX-License-Identifier: MIT defmodule AshSqlite.Transformers.VerifyRepo do @moduledoc false use Spark.Dsl.Transformer alias Spark.Dsl.Transformer def after_compile?, do: true def transform(dsl) do repo = Transformer.get_option(dsl, [:sqlite], :repo) cond do is_function(repo) -> {:ok, dsl} match?({:error, _}, Code.ensure_compiled(repo)) -> {:error, "Could not find repo module #{repo}"} repo.__adapter__() != Ecto.Adapters.SQLite3 -> {:error, "Expected a repo using the sqlite adapter `Ecto.Adapters.SQLite3`"} true -> {:ok, dsl} end end end