Tursox.Pool (tursox v0.2.1)

Copy Markdown View Source

Optional DBConnection pool whose workers derive connections from one database.

Starting a pool with a path owns exactly one database resource. Passing an existing Tursox.Database leaves it caller-owned unless own_database: true.

Summary

Functions

Closes a prepared query on one checked-out worker.

Executes a write/DDL statement through DBConnection.

Returns redacted ownership and database metadata.

Returns the underlying DBConnection pool PID.

Prepares a reusable query through DBConnection.

Executes a bounded materialized query through DBConnection.

Starts a shared-handle DBConnection pool.

Stops the pool, drains workers, and closes an owned database.

Returns a checkout-bound bounded DBConnection stream.

Runs a DBConnection transaction with the requested Tursox mode.

Functions

close(pool, query, opts \\ [])

Closes a prepared query on one checked-out worker.

execute(pool, sql, params \\ [], opts \\ [])

@spec execute(GenServer.server() | DBConnection.t(), String.t(), term(), keyword()) ::
  {:ok, Tursox.Result.t()} | {:error, Exception.t()}

Executes a write/DDL statement through DBConnection.

execute_prepared(pool, query, params \\ [], opts \\ [])

Executes a query returned by prepare/4.

metadata(owner)

Returns redacted ownership and database metadata.

pool(connection)

@spec pool(GenServer.server() | DBConnection.t()) :: pid() | DBConnection.t()

Returns the underlying DBConnection pool PID.

prepare(pool, sql, command \\ :query, opts \\ [])

@spec prepare(
  GenServer.server() | DBConnection.t(),
  String.t(),
  :query | :execute,
  keyword()
) ::
  {:ok, Tursox.Query.t()} | {:error, Exception.t()}

Prepares a reusable query through DBConnection.

query(pool, sql, params \\ [], opts \\ [])

@spec query(GenServer.server() | DBConnection.t(), String.t(), term(), keyword()) ::
  {:ok, Tursox.Result.t()} | {:error, Exception.t()}

Executes a bounded materialized query through DBConnection.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts a shared-handle DBConnection pool.

stop(pool, timeout \\ 15000)

@spec stop(GenServer.server(), timeout()) :: :ok

Stops the pool, drains workers, and closes an owned database.

stream(pool, sql, params \\ [], opts \\ [])

@spec stream(GenServer.server() | DBConnection.t(), String.t(), term(), keyword()) ::
  Enumerable.t()

Returns a checkout-bound bounded DBConnection stream.

transaction(pool, fun, opts \\ [])

Runs a DBConnection transaction with the requested Tursox mode.