Skip to contents

Easily connect to a database. When connecting to a database for the first time, you will be prompted for connection details. Configuration details will be stored in the user-specified 'configuration file'. The next time you run the same command, config details will be automatically retreived from the config file. Any usernames and passwords are stored in your system credential manager (not on-disk)

Usage

easydb_connect(dbname, config_file, from_scratch = FALSE)

Arguments

dbname

name of database (string)

config_file

path to yaml file containing configuration information about databases (port, host, etc. ) (string)

from_scratch

should we delete any current config / credentials for databases with the supplied name and start again? (logical)

Value

connection to database (connection)

Examples

if(interactive()) {

  # Choose config file path
  # Do NOT use tempfile in practice.
  # Instead, choose a fixed location such as '~/.easydb'
  config <- tempfile('.example_config')

  # Initialise config file
  easydb_init(config)

  # Connect to SQLite database
  path_to_db <- system.file(package = 'easydb', 'testdbs/mtcars.sqlite')
  con <- easydb_connect(dbname = path_to_db, config_file = config)

  # Disconnect from database when finished
  easydb_disconnect(con)
}