Description Usage Arguments Examples
A wrapper around poolCreate
to simplify the creation of a DBI
database connection pool. Check the documentation of poolCreate()
for a generic overview of the parent function and the Pool object. The
main thing to point out is that, for dbPool
, you always need to
provide a DBI driver (i.e. of class DBI::DBIDriver-class()
),
and it should always be accompanied by the required authorization
arguments (see the example below).
1 |
drv |
An object that inherits from |
... |
Arguments needed for both
|
validateQuery |
The query to run to verify that the connection
is valid (it should be as simple as possible). If this is not
provided, |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # Using the RMySQL package
if (requireNamespace("RMySQL", quietly = TRUE)) {
pool <- dbPool(
drv = RMySQL::MySQL(),
dbname = "shinydemo",
host = "shiny-demo.csa7qlmguqrf.us-east-1.rds.amazonaws.com",
username = "guest",
password = "guest"
)
dbGetQuery(pool, "SELECT * from City LIMIT 5;")
#> ID Name CountryCode District Population
#> 1 1 Kabul AFG Kabol 1780000
#> 2 2 Qandahar AFG Qandahar 237500
#> 3 3 Herat AFG Herat 186800
#> 4 4 Mazar-e-Sharif AFG Balkh 127800
#> 5 5 Amsterdam NLD Noord-Holland 731200
poolClose(pool)
} else {
message("Please install the 'RMySQL' package to run this example")
}
# Using a DSN with an ODBC driver
## Not run:
pool <- dbPool(odbc::odbc(), dsn = "Data Source Name")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.