Connect to a database, either supply connection details though a config file or connect to local default database.

psql_connect(
  config_path = getOption("psql.config_path", NULL),
  config_value = getOption("psql.config_value", "default")
)

Arguments

config_path

A string of a file path to the yaml configuration file. The default value grabs the file path from the psql.config_path option and uses NULL if no value supplied.

config_value

A string of the name of value. The default value grabs the value from the psql.config_value option and uses "default" if no value is supplied.

Value

An S4 object that inherits from DBIConnection.

Details

The yml file can contain connection details for: host, port, dbname, user and password. The host, database name, user name and password should be passed as string. The port is passed as an integer. The function uses config::get() to read the config file, check there for more information on reading in the config data.

If no config details are passed it will connect to your local cluster.

Set the values for psql.config_path and psql.config_value for the function to grab config details. The values can be set options().

Examples

if (FALSE) { # \dontrun{
conn <- psql_connect()
DBI::dbDisconnect(conn)

psql_connect("config.yml")
DBI::dbDisconnect(conn)

psql_connect(config_path = "config.yml", config_value = "database")
DBI::dbDisconnect(conn)
} # }