Opens (or creates) a per-user SQL cache database. This is the opt-in SQL backend and requires DuckDB or RSQLite to be installed.
Details
Note: the DEFAULT cache used by morie_cache_store() / _load() /
_list() needs no SQL backend at all — it uses a zero/light
dependency file store: Parquet via nanoparquet (cross-language)
when available, else base-R .rds. Install duckdb (or RSQLite),
or set MORIE_CACHE_BACKEND=duckdb/sqlite, or pass db_path=, to
use SQL instead — DuckDB is preferred (vectorised + columnar, handles
multi-GB PUMFs and out-of-core analytical queries); an existing
morie.db / morie.duckdb cache is reused for back-compat. For the
multi-user server tier, pass your own PostgreSQL con=.
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)
}
#> duckdb is keeping downloaded extensions in a temporary directory:
#> ℹ /tmp/RtmpOKyZlD/duckdb/extensions
#> This is removed when the R session ends, so extensions are re-downloaded each session.
#> ℹ To keep them, point `options(duckdb.extension_directory =)` or the `DUCKDB_EXTENSION_DIRECTORY` environment variable at a permanent path.
#> [1] TRUE
# }
