Establishes a connection to the PostgreSQL database using credentials from
environment variables or taskqueue_options(). If a valid connection
is provided, it returns that connection instead of creating a new one.
Details
Connection parameters are read from environment variables set in .Renviron:
PGHOST: Database server hostnamePGPORT: Database server port (typically 5432)PGUSER: Database usernamePGPASSWORD: Database passwordPGDATABASE: Database name
The function automatically sets client_min_messages to WARNING to
reduce console output noise.
Examples
if (FALSE) { # \dontrun{
# Not run:
# Create a new connection
con <- db_connect()
# Reuse existing connection
con2 <- db_connect(con)
# Always disconnect when done
db_disconnect(con)
} # }