Establishes a connection pool to a PostgreSQL database (e.g. Supabase) using
credentials from a .env file. The survey operating mode ("database",
"preview", or "local") is controlled via the mode key under
survey-settings in survey.qmd, not by this function.
Arguments
- env_file
Character string. Path to the env file. Defaults to
".env".- ignore
Logical. Deprecated. Use
mode: previewinsurvey.qmdYAML instead. IfTRUE, returnsNULLwith a deprecation warning. Defaults toNULL.- gssencmode
Character string. The GSS encryption mode for the database connection. Defaults to
"auto". Options are:"auto": Tries"prefer"first, then falls back to"disable"if GSSAPI negotiation fails"prefer": Uses GSSAPI encryption if available, plain connection otherwise"disable": Disables GSSAPI encryption entirely NOTE: If you have verified all connection details are correct but still cannot access the database, try setting this to"disable".
Value
A list containing:
db: The database connection pooltable: The database table name
Returns NULL if the database connection fails or ignore = TRUE.
Examples
if (interactive()) {
db <- sd_db_connect()
# Close connection when done
if (!is.null(db$db)) {
pool::poolClose(db$db)
}
}
