db_connection v1.1.0 DBConnection.Pool behaviour
A behaviour module for implementing a pool of database connections
using DBConnection
.
Summary
Callbacks
Checkin a connection’s state to the pool
Checkout a connection’s state from a pool
Create a supervisor child specification for the pool with module
module
, options opts
and child specification options child_opts
Checkin a connection’s state to the pool and disconnect it with an exception
Ensure all applications necessary to run the pool are started
Start and link to a pool of module
connections with options opts
Stop a connection
Callbacks
Specs
checkin(pool_ref :: any, state :: any, opts :: Keyword.t) :: :ok
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.
Specs
checkout(pool :: GenServer.server, opts :: Keyword.t) ::
{:ok, pool_ref :: any, module, state :: any} |
{:error, Exception.t}
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.
Specs
child_spec(module, opts :: Keyword.t, child_opts :: Keyword.t) :: Supervisor.Spec.spec
Create a supervisor child specification for the pool with module
module
, options opts
and child specification options child_opts
.
Specs
disconnect(pool_ref :: any, err :: Exception.t, state :: any, opts :: Keyword.t) :: :ok
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.
Specs
ensure_all_started(opts :: Keyword.t, type :: :application.restart_type) ::
{:ok, [atom]} |
{:error, atom}
Ensure all applications necessary to run the pool are started.
Specs
start_link(module, opts :: Keyword.t) :: GenServer.on_start
Start and link to a pool of module
connections with options opts
.
Specs
stop(pool_ref :: any, err :: Exception.t, state :: any, opts :: Keyword.t) :: :ok
Stop a connection.
The pool_ref
is from the return of checkout/2
.
state
is the lastest state of the connection.