db_connection v1.1.3 DBConnection.Pool behaviour View Source

A behaviour module for implementing a pool of database connections using DBConnection.

Link to this section 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

Link to this section Callbacks

Link to this callback checkin(pool_ref, state, opts) View Source
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.

Link to this callback checkout(pool, opts) View Source
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.

Link to this callback child_spec(module, opts, child_opts) View Source
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.

Link to this callback disconnect(pool_ref, err, state, opts) View Source
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.

Link to this callback ensure_all_started(opts, type) View Source
ensure_all_started(opts :: Keyword.t(), type :: :application.restart_type()) ::
  {:ok, [atom()]} |
  {:error, atom()}

Ensure all applications necessary to run the pool are started.

Link to this callback start_link(module, opts) View Source
start_link(module(), opts :: Keyword.t()) :: GenServer.on_start()

Start and link to a pool of module connections with options opts.

Link to this callback stop(pool_ref, err, state, opts) View Source
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.