Packages
db_connection
0.1.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/pool.ex
defmodule DBConnection.Pool do
@moduledoc """
A behaviour module for implementing a pool of database connections
using `DBConnection`.
"""
@doc """
Start and link to a pool of `module` connections with options `opts`.
"""
@callback start_link(module, opts :: Keyword.t) ::
GenServer.on_start
@doc """
Create a supervisor child specification for the pool with module
`module`, options `opts` and child specification options `child_opts`.
"""
@callback child_spec(module, opts :: Keyword.t, child_opts :: Keyword.t) ::
Supervisor.Spec.spec
@doc """
Checkout a connection's state from a pool.
The returned `pool_ref` will be passed to `checkin/3`, `disconnect/4`
and `stop/4`.
`module` and `state` are the module and state of the connection.
"""
@callback checkout(pool :: GenServer.server, opts :: Keyword.t) ::
{:ok, pool_ref :: any, module, state :: any} | :error
@doc """
Checkin a connection's state to the pool.
The `pool_ref` is from the return of `checkout/2`.
`state` is the lastest state of the connection.
"""
@callback checkin(pool_ref :: any, state :: any, opts :: Keyword.t) :: :ok
@doc """
Checkin a connection's state to the pool and disconnect it with an
exception.
The `pool_ref` is from the return of `checkout/2`.
`state` is the lastest state of the connection.
"""
@callback disconnect(pool_ref :: any, err :: Exception.t, state :: any, opts :: Keyword.t) ::
:ok
@doc """
Stop a connection.
The `pool_ref` is from the return of `checkout/2`.
`reason` is any term.
`state` is the lastest state of the connection.
"""
@callback stop(pool_ref :: any, reason :: any, state :: any, opts :: Keyword.t) ::
:ok
end