Packages
db_connection
0.2.4
2.10.2
2.10.1
2.10.0
2.9.0
2.8.1
2.8.0
2.7.0
2.6.0
2.5.0
2.4.3
2.4.2
2.4.1
2.4.0
2.3.1
2.3.0
2.2.2
2.2.1
2.2.0
2.1.1
2.1.0
2.0.6
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
2.0.0-rc.0
1.1.3
1.1.2
1.1.1
1.1.0
1.0.0
1.0.0-rc.5
1.0.0-rc.4
1.0.0-rc.3
1.0.0-rc.2
1.0.0-rc.1
1.0.0-rc.0
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Database connection behaviour for database transactions and connection pooling
Current section
Files
Jump to
Current section
Files
lib/db_connection/sojourn/broker.ex
defmodule DBConnection.Sojourn.Broker do
@moduledoc false
if Code.ensure_loaded?(:sbroker) do
@behaviour :sbroker
end
@pool {__MODULE__, :pool_sup}
@doc false
def init({broker, mod, opts}) do
opts = Keyword.put(opts, :pool_sup, pool(mod, opts))
apply(broker, :init, [opts])
end
## Helpers
defp pool(mod, opts) do
Process.get(@pool) || start_pool(mod, opts)
end
defp start_pool(mod, opts) do
{:ok, pid} = DBConnection.Sojourn.Supervisor.start_pool(mod, opts)
_ = Process.put(@pool, pid)
pid
end
end