Return a connection to be used for caching
Usage
cas_connect_to_db(
db_connection = NULL,
use_db = NULL,
db_type = NULL,
db_folder = NULL,
read_only = FALSE,
...
)
Arguments
- db_connection
Defaults to NULL. If NULL, uses local SQLite database. If given, must be a connection object or a list with relevant connection settings (see example).
- use_db
Defaults to NULL. If given, it should be given either TRUE or FALSE. Typically set with
cas_enable_db()
orcas_disable_db()
.- read_only
Defaults to FALSE. Passed to
DBI::dbConnect
.- ...
Passed to
cas_get_db_file()
.
See also
Other database functions:
cas_check_db_folder()
,
cas_check_use_db()
,
cas_create_db_folder()
,
cas_disable_db()
,
cas_disconnect_from_db()
,
cas_enable_db()
,
cas_get_db_settings()
,
cas_read_from_db()
,
cas_set_db()
,
cas_set_db_folder()
,
cas_write_to_db()
Examples
# \donttest{
if (interactive()) {
db_connection <- DBI::dbConnect(
RSQLite::SQLite(), # or e.g. odbc::odbc(),
Driver = ":memory:", # or e.g. "MariaDB",
Host = "localhost",
database = "example_db",
UID = "example_user",
PWD = "example_pwd"
)
cas_connect_to_db(db_connection)
db_settings <- list(
driver = "MySQL",
host = "localhost",
port = 3306,
database = "castarter",
user = "secret_username",
pwd = "secret_password"
)
cas_connect_to_db(db_settings)
}
# }