db_connect
Get a database connection
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
| Argument | Description |
|---|---|
name
|
Character. Name of the connection in config.yml (e.g., "postgres") |
Returns
A database connection object (DBIConnection)
Examples
# 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)
Source: R/connections.R