Skip to content

Commit

Permalink
improvement: Add builtin support for ash_sqlite. (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
djgoku authored Sep 6, 2024
1 parent c132d94 commit 8aa7257
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/resource/transformers/create_version_resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ defmodule AshPaperTrail.Resource.Transformers.CreateVersionResource do
{false, nil, nil}
end

{sqlite?, table, repo} =
if data_layer == AshSqlite.DataLayer do
{true, apply(AshSqlite.DataLayer.Info, :table, [dsl_state]), apply(AshSqlite.DataLayer.Info, :repo, [dsl_state])}

Check warning on line 41 in lib/resource/transformers/create_version_resource.ex

View workflow job for this annotation

GitHub Actions / ash-ci / mix credo --strict

Line is too long (max is 120, was 121).
else
{false, nil, nil}
end

{ets?, private?} =
if data_layer == Ash.DataLayer.Ets do
{true, Ash.DataLayer.Ets.Info.private?(dsl_state)}
Expand Down Expand Up @@ -151,6 +158,36 @@ defmodule AshPaperTrail.Resource.Transformers.CreateVersionResource do
)
end

if unquote(sqlite?) do
table = unquote(table)
repo = unquote(repo)
reference_source? = unquote(reference_source?)
belongs_to_actors = unquote(Macro.escape(belongs_to_actors))

Code.eval_quoted(
quote do
sqlite do
table(unquote(table) <> "_versions")
repo(unquote(repo))

references do
unless unquote(reference_source?) do
reference(:version_source, ignore?: true)
end

for actor_relationship <- unquote(Macro.escape(belongs_to_actors)) do
unless actor_relationship.define_attribute? do
reference(actor_relationship.name, on_delete: :nothing, on_update: :update)
end
end
end
end
end,
[],
__ENV__
)
end

if unquote(ets?) do
private? = unquote(private?)

Expand Down

0 comments on commit 8aa7257

Please sign in to comment.