1
0
mirror of https://github.com/algora-io/tv.git synced 2025-01-05 01:20:24 +02:00
algora-tv/lib/algora/repo.ex
2024-02-29 22:31:42 +03:00

24 lines
559 B
Elixir

defmodule Algora.Repo do
use Ecto.Repo,
otp_app: :algora,
adapter: Ecto.Adapters.Postgres
def replica, do: Algora.config([:replica])
@locks %{playlist: 1}
def multi_transaction_lock(multi, scope, id) when is_atom(scope) and is_integer(id) do
scope_int = Map.fetch!(@locks, scope)
Ecto.Multi.run(multi, scope, fn repo, _changes ->
repo.query("SELECT pg_advisory_xact_lock(#{scope_int}, #{id})")
end)
end
end
defmodule Algora.ReplicaRepo do
use Ecto.Repo,
otp_app: :algora,
adapter: Ecto.Adapters.Postgres
end