sd_database {surveydown} | R Documentation |
Connect to a 'PostgreSQL' Database with Automatic Cleanup
Description
This function establishes a connection pool to a 'PostgreSQL' database (e.g. Supabase) and sets up automatic cleanup when the 'shiny' session ends.
Usage
sd_database(
host = NULL,
dbname = NULL,
port = NULL,
user = NULL,
table = NULL,
password = Sys.getenv("SURVEYDOWN_PASSWORD"),
gssencmode = "prefer",
ignore = FALSE,
min_size = 1,
max_size = Inf
)
Arguments
host |
Character string. The host address of the PostgreSQL database. |
dbname |
Character string. The name of the PostgreSQL database. |
port |
Integer. The port number for the PostgreSQL database connection. |
user |
Character string. The username for the PostgreSQL database connection. |
table |
Character string. The name of the table to interact with in the Supabase database. |
password |
Character string. The password for the PostgreSQL database
connection. NOTE: While you can provide a hard-coded password here, we do
NOT recommend doing so for security purposes. Instead, you should establish
a password with |
gssencmode |
Character string. The GSS encryption mode for the database
connection. Defaults to |
ignore |
Logical. If |
min_size |
Integer. The minimum number of connections in the pool. Defaults to 1. |
max_size |
Integer. The maximum number of connections in the pool.
Defaults to |
Value
A list containing the database connection pool (db
) and the table
name (table
), or NULL
if in ignore mode or if there's an error.
Examples
if (interactive()) {
# Assuming SURVEYDOWN_PASSWORD is set in .Renviron
db <- sd_database(
host = "aws-0-us-west-1.pooler.supabase.com",
dbname = "postgres",
port = "6---",
user = "postgres.k----------i",
table = "your-table-name",
ignore = FALSE
)
# Print the structure of the connection
str(db)
# Close the connection pool when done
if (!is.null(db)) {
pool::poolClose(db$db)
}
}