View source: R/connection_pool.R
| connection_pool | R Documentation |
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.
connection_pool(
name,
min_size = 1,
max_size = Inf,
idle_timeout = 60,
validation_interval = 60,
recreate = FALSE
)
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) |
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)
A pool object that can be used like a regular DBI connection
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.