connection_pool: Get or create a connection pool

View source: R/connection_pool.R

connection_poolR Documentation

Get or create a connection pool

Description

Returns a connection pool for the specified database connection. Connection pools automatically manage connection lifecycle, reuse connections across operations, and handle cleanup. This is the recommended way to work with databases in Framework.

Usage

connection_pool(
  name,
  min_size = 1,
  max_size = Inf,
  idle_timeout = 60,
  validation_interval = 60,
  recreate = FALSE
)

Arguments

name

Character. Name of the connection in settings.yml

min_size

Integer. Minimum number of connections to maintain (default: 1)

max_size

Integer. Maximum number of connections allowed (default: Inf)

idle_timeout

Integer. Seconds before idle connections are closed (default: 60)

validation_interval

Integer. Seconds between connection health checks (default: 60)

recreate

Logical. If TRUE, closes existing pool and creates new one (default: FALSE)

Details

Connection pools are stored in a package environment and reused across calls. You don't need to manage pool lifecycle - Framework handles it automatically.

Advantages of connection pools:

  • Automatic connection reuse (faster than creating new connections)

  • Handles connection failures gracefully (auto-reconnects)

  • Thread-safe for Shiny apps

  • No need to manually disconnect

  • Health checking prevents using stale connections

When to use:

  • Long-running R sessions (notebooks, Shiny apps)

  • Multiple database operations

  • Any production code

When NOT to use:

  • One-off queries (use query_get() instead)

  • Short scripts (overhead not worth it)

Value

A pool object that can be used like a regular DBI connection


framework documentation built on Feb. 18, 2026, 1:07 a.m.