Connect to a database using YAML configs
db_connect(db, cache, ...)
db | name of database, must be present in the file specified by |
---|---|
cache | optional caching of the connection. If set to |
... | extra parameters passed to the database driver, even ones overriding the default values loaded from the YAML config |
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) }