Skip to content

Commit

Permalink
Reduce compile-time dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnenterprise committed Oct 29, 2022
1 parent c753dd2 commit 1b648ef
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/projections/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,20 @@ defmodule Commanded.Projections.Ecto do
schema_prefix =
opts[:schema_prefix] || Application.get_env(:commanded_ecto_projections, :schema_prefix)

timeout = opts[:timeout] || :infinity
handler_opts = Keyword.drop(opts, [:repo, :schema_prefix, :timeout])

quote location: :keep do
@behaviour Commanded.Projections.Ecto

@opts unquote(opts)
@repo @opts[:repo] || Application.compile_env(:commanded_ecto_projections, :repo) ||
@repo unquote(opts[:repo]) || Application.compile_env(:commanded_ecto_projections, :repo) ||
raise("Commanded Ecto projections expects :repo to be configured in environment")
@timeout @opts[:timeout] || :infinity

# Pass through any other configuration to the event handler
@handler_opts Keyword.drop(@opts, [:repo, :schema_prefix, :timeout])

unquote(__include_schema_prefix__(schema_prefix))
unquote(__include_projection_version_schema__())

use Ecto.Schema
use Commanded.Event.Handler, @handler_opts
use Commanded.Event.Handler, unquote(handler_opts)

import Ecto.Changeset
import Ecto.Query
Expand Down Expand Up @@ -106,7 +104,7 @@ defmodule Commanded.Projections.Ecto do
end

defp transaction(%Ecto.Multi{} = multi) do
@repo.transaction(multi, timeout: @timeout, pool_timeout: @timeout)
@repo.transaction(multi, timeout: unquote(timeout), pool_timeout: unquote(timeout))
end

defoverridable schema_prefix: 1, schema_prefix: 2
Expand Down

0 comments on commit 1b648ef

Please sign in to comment.