db_connect: Get a database connection

View source: R/connections.R

db_connectR Documentation

Get a database connection

Description

Gets a database connection based on the connection name in config.yml. For most use cases, prefer db_query() or db_execute() which handle connection lifecycle automatically.

Usage

db_connect(name)

Arguments

name

Character. Name of the connection in config.yml (e.g., "postgres")

Value

A database connection object (DBIConnection)

Examples


if (FALSE) {
# Preferred: use db_query() which auto-disconnects
users <- db_query("SELECT * FROM users", "postgres")

# Manual connection management (remember to disconnect!)
conn <- db_connect("postgres")
DBI::dbListTables(conn)
DBI::dbDisconnect(conn)
}



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