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{
if (morie_has("sql")) withAutoprint({
# 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)
}
})
#> > 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
# }
