mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
27 lines
594 B
Elixir
27 lines
594 B
Elixir
defmodule Philomena.Repo do
|
|
alias Ecto.Multi
|
|
|
|
use Ecto.Repo,
|
|
otp_app: :philomena,
|
|
adapter: Ecto.Adapters.Postgres
|
|
|
|
use Scrivener, page_size: 250
|
|
|
|
@levels %{
|
|
read_committed: "READ COMMITTED",
|
|
repeatable_read: "REPEATABLE READ",
|
|
serializable: "SERIALIZABLE"
|
|
}
|
|
|
|
def isolated_transaction(%Multi{} = multi, level) do
|
|
Multi.append(
|
|
Multi.new()
|
|
|> Multi.run(:isolate, fn repo, _chg ->
|
|
repo.query!("SET TRANSACTION ISOLATION LEVEL #{@levels[level]}")
|
|
{:ok, nil}
|
|
end),
|
|
multi
|
|
)
|
|
|> Philomena.Repo.transaction()
|
|
end
|
|
end
|