db_connect: Connect to a database using YAML configs

Description Usage Arguments See Also Examples

View source: R/db.R

Description

Connect to a database using YAML configs

Usage

1
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

db_close db_query

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
## 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)

## End(Not run)

daroczig/dbr documentation built on June 12, 2020, 2:47 p.m.