This is a convenience wrapper for DBI::dbConnect() for different database backends.
Connects to the specified dbname of host:port using user and password from given arguments (if applicable). Certain drivers may use credentials stored in a file, such as ~/.pgpass (PostgreSQL).
get_connection(drv, ...)# S3 method for SQLiteDriver
get_connection(
drv,
dbname = ":memory:",
...,
bigint = c("integer", "bigint64", "numeric", "character")
)
# S3 method for PqDriver
get_connection(
drv,
dbname = NULL,
host = NULL,
port = NULL,
password = NULL,
user = NULL,
...,
bigint = c("integer", "bigint64", "numeric", "character"),
check_interrupts = TRUE,
timezone = Sys.timezone(),
timezone_out = Sys.timezone()
)
# S3 method for OdbcDriver
get_connection(
drv,
dsn = NULL,
...,
bigint = c("integer", "bigint64", "numeric", "character"),
timezone = Sys.timezone(),
timezone_out = Sys.timezone()
)
# S3 method for duckdb_driver
get_connection(
drv,
dbdir = ":memory:",
...,
bigint = c("numeric", "character"),
timezone_out = Sys.timezone()
)
# S3 method for default
get_connection(drv, ...)
An object that inherits from DBIConnection driver specified in drv.
(DBIDriver(1) or DBIConnection(1))
The driver for the connection (defaults to SQLiteDriver).
Additional parameters sent to DBI::dbConnect().
(character(1))
Name of the database located at the host.
(character(1))
The datatype to convert integers to.
Support depends on the database backend.
(character(1))
The ip of the host to connect to.
(numeric(1) or character(1))
Host port to connect to.
(character(1))
Password to login with.
(character(1))
Username to login with.
(logical(1))
Should user interrupts be checked during the query execution?
(character(1))
Sets the timezone of DBI::dbConnect(). Must be in OlsonNames().
(character(1))
Sets the timezone_out of DBI::dbConnect(). Must be in OlsonNames().
(character(1))
The data source name to connect to.
(character(1))
The directory where the database is located.
RSQLite::SQLite
RPostgres::Postgres
odbc::odbc
duckdb::duckdb
if (FALSE) { # requireNamespace("RSQLite", quietly = TRUE)
conn <- get_connection(drv = RSQLite::SQLite(), dbname = ":memory:")
DBI::dbIsValid(conn) # TRUE
close_connection(conn)
DBI::dbIsValid(conn) # FALSE
}
Run the code above in your browser using DataLab