Connect to a database using YAML configs

db_connect(db, cache, ...)

Arguments

db

name of database, must be present in the file specified by getOption('dbr.db_config_path')

cache

optional caching of the connection. If set to TRUE, the connection will be cached in the background and an all future db_connect calls will simply return that (even if called automatically from eg db_query) until the end of the R session or when caching on the db is disabled in a future db_connect call with explic cache = FALSE. See the examples for more details.

...

extra parameters passed to the database driver, even ones overriding the default values loaded from the YAML config

See also

Examples

if (FALSE) { ## create new connection optbak <- options() options('dbr.db_config_path' = system.file('example_db_config.yaml', package = 'dbr')) con <- db_connect('sqlite') str(con) db_query('SELECT 42', 'sqlite') ## reusing the connection str(db_connect('sqlite', cache = TRUE)) str(db_connect('sqlite')) str(db_connect('sqlite')) ## kill cached connection db_close(db_connect('sqlite', cache = FALSE)) ## restore options options(optbak) }