Skip to content

Commit 0325196

Browse files
committed
improvement: allow for combining AshPostgres.Repo with other repos
fixes #172
1 parent 41c34b8 commit 0325196

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

lib/data_layer.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ defmodule AshPostgres.DataLayer do
391391
sections: @sections,
392392
transformers: [
393393
AshPostgres.Transformers.ValidateReferences,
394-
AshPostgres.Transformers.VerifyRepo,
395394
AshPostgres.Transformers.EnsureTableOrPolymorphic,
396395
AshPostgres.Transformers.PreventMultidimensionalArrayAggregates
397396
]
@@ -502,7 +501,7 @@ defmodule AshPostgres.DataLayer do
502501
def can?(_, :timeout), do: true
503502
def can?(_, {:filter_expr, _}), do: true
504503
def can?(_, :nested_expressions), do: true
505-
def can?(_, {:query_aggregate, :count}), do: true
504+
def can?(_, {:query_aggregate, _}), do: true
506505
def can?(_, :sort), do: true
507506
def can?(_, :distinct_sort), do: true
508507
def can?(_, :distinct), do: true

lib/repo.ex

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ defmodule AshPostgres.Repo do
4545
Use this to inform the data layer about the oldest potential postgres version it will be run on.
4646
4747
Must be an integer greater than or equal to 13.
48+
49+
## Combining with other tools
50+
51+
For things like `Fly.Repo`, where you might need to have more fine grained control over the repo module,
52+
you can use the `define_ecto_repo?: false` option to `use AshPostgres.Repo`.
4853
"""
4954
@callback min_pg_version() :: integer()
5055

@@ -63,11 +68,13 @@ defmodule AshPostgres.Repo do
6368

6469
defmacro __using__(opts) do
6570
quote bind_quoted: [opts: opts] do
66-
otp_app = opts[:otp_app] || raise("Must configure OTP app")
71+
if Keyword.get(opts, :define_ecto_repo?, true) do
72+
otp_app = opts[:otp_app] || raise("Must configure OTP app")
6773

68-
use Ecto.Repo,
69-
adapter: Ecto.Adapters.Postgres,
70-
otp_app: otp_app
74+
use Ecto.Repo,
75+
adapter: Ecto.Adapters.Postgres,
76+
otp_app: otp_app
77+
end
7178

7279
@behaviour AshPostgres.Repo
7380

lib/transformers/verify_repo.ex

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)