Skip to contents

Like episodic_db_connect(), but falls back to the EPISODIC_DB environment variable when you do not pass a path explicitly - handy for one-off console use, e.g. episodic_add_user() uses it internally so adding an account needs only a username and password, not a connection you build yourself first.

Usage

episodic_db_open(
  db_path = Sys.getenv("EPISODIC_DB", unset = NA),
  check_schema_version = TRUE
)

Arguments

db_path

Path to an existing SQLite database, or a mysql:// DSN (see episodic_db_dsn_mariadb()). Defaults to the EPISODIC_DB environment variable.

check_schema_version

Whether to refuse a database whose schema version is not the one this build of EpiSODIC expects, with an error naming episodic_db_migrate() as the fix. TRUE (the default) everywhere except inside episodic_db_migrate() itself, which by definition has to open a database that is out of date.

Value

An open DBI::DBIConnection; you are responsible for disconnecting it.

Examples

db_path <- tempfile(fileext = ".sqlite")
con <- episodic_db_create(db_path)
DBI::dbDisconnect(con)
Sys.setenv(EPISODIC_DB = db_path)
con <- episodic_db_open()
DBI::dbDisconnect(con)
file.remove(db_path)
#> [1] TRUE