Skip to contents

Opens (or creates) the per-user cache database. The default backend is DuckDB — zero-config like SQLite, but vectorised + columnar, so it handles the multi-GB-scale open-data PUMFs (TPS, CPADS bulk) that morie ingests without breaking down on analytical queries. For back-compat, an existing SQLite cache at morie.db is reused; if duckdb is unavailable, falls back to SQLite.

Usage

morie_db_connect(db_path = NULL)

Arguments

db_path

Optional path to a DuckDB (*.duckdb) or SQLite (*.db) file. Defaults to the MORIE_CACHE_DB env var, else morie.duckdb / morie.db in the per-user cache directory.

Value

A DBI connection object.

Details

For non-default backends (PostgreSQL, MariaDB, MS SQL Server, ...), construct your own DBI connection and pass it as con to the morie_cache_* and morie_load_dataset functions:


con <- DBI::dbConnect(RPostgres::Postgres(),
  host = "...", dbname = "morie", user = "...", password = "...")
morie_load_dataset("ocp21", con = con)

Examples

# \donttest{
# DuckDB (default when 'duckdb' is installed); pass a '.db' path for SQLite.
if (requireNamespace("duckdb", quietly = TRUE) &&
  requireNamespace("DBI", quietly = TRUE)) {
  tmp <- tempfile(fileext = ".duckdb")
  con <- morie_db_connect(db_path = tmp)
  DBI::dbListTables(con)
  DBI::dbDisconnect(con)
  file.remove(tmp)
}
#> [1] TRUE
# }