With dsn, a thin wrapper around DBI::dbConnect() over odbc::odbc()
with one deliberate choice: bigint = "numeric". Under the odbc
default a BIGINT column arrives as integer64, and is.numeric() of an
integer64 is FALSE: typing would treat the column as a categorical of
very high cardinality. With driver, any DBI driver object is accepted
(e.g. RSQLite::SQLite(), duckdb::duckdb()), which is how the database
path is tested without a DSN.
Arguments
- dsn
Name of the DSN configured on the system. Ignored when
driveris given.- driver
Optional DBI driver object, used instead of ODBC.
- timeout
Connection timeout in seconds (ODBC only).
- ...
Extra arguments passed on to
DBI::dbConnect()(for exampledbname = ":memory:"for SQLite).
Value
A DBI connection. Close it with DBI::dbDisconnect().
See also
Other database:
scr_fetch()
Examples
con <- scr_connect(driver = RSQLite::SQLite(), dbname = ":memory:")
d <- scr_demo; d$ref_date <- as.character(d$ref_date) # SQLite has no Date type
DBI::dbWriteTable(con, "dtm", d)
dt <- scr_fetch(con, "dtm", sample_frac = 0.5, seed = 42)
#> SQL: select * from dtm where ((abs(random()) % 1000000) / 1000000.0) <= 0.5
nrow(dt)
#> [1] 2098
DBI::dbDisconnect(con)
