Create a class representing a connection to a MareFrame DB

mfdb(schema_name,
db_params = list(),
destroy_schema = FALSE,
save_temp_tables = FALSE)

mfdb_disconnect(mdb)

## Arguments

schema_name This can be one of: Postgresql schema name A file path ending with ".sqlite" to connect to a SQLite file database A file path ending with ".duckdb" to connect to a DuckDB file database If connecting to a SQLite/DuckDB database, db_params should remain empty ( schema_name will be used as a dbname). If connecting to a Postgres database, it can be used to store any number of case studies, by storing them in separate schemas. This parameter defines the schema to connect to, and can contain any lower case characters or underscore. Extra parameters to supply to DBI::dbConnect. By default it will search for a "mf" database locally, but you can override any of the parameters, in particular host, dbname, user, password. See ?RPostgres::Postgres for more information. If dbname looks like a SQLite database filename, then MFDB will use the RSQLite driver. If dbdir is set, then MFDB will use the duckdb driver. Otherwise, RPostgres will be used. db_params can also be supplied by environment variable, for example if a MFDB_DBNAME environment variable is set then it will be used instead of any dbname supplied here. Optional boolean. If true, all mfdb tables will be destroyed when connecting. This allows you to start populating your case study from scratch if required. The function will return NULL, you need to call mfdb again to connect, at which point the mfdb tables will be recreated and you can populate with data again. Optional boolean. If true, any temporary tables will be made permanent for later inspection. Database connection created by mfdb().

## Value

A 'mfdb' object representing the DB connection

## Examples

# Connect to a SQLite database file
mdb <- mfdb(tempfile(fileext = '.sqlite'))
#> 2021-10-15 14:03:35 INFO:mfdb:Creating schema from scratch
#> 2021-10-15 14:03:35 INFO:mfdb:Taxonomy market_category no updates to make
#> 2021-10-15 14:03:35 INFO:mfdb:Schema up-to-datemfdb_disconnect(mdb)

if (FALSE) # NB: Requires a PostgreSQL installation, see README

# Connect to local DB, as the "examples" case study
mdb <- mfdb('examples')
mfdb_disconnect(mdb)