library(sqlhelper)
readLines(
system.file("examples/sqlhelper_db_conf.yml",
package="sqlhelper")
) |>
writeLines()
connect(
system.file("examples/sqlhelper_db_conf.yml", package="sqlhelper"),
exclusive=TRUE)
DBI::dbWriteTable( default_conn(),
"iris",
iris)
n <- 5
run_queries(
c(top_n = "select * from iris limit {n}",
uniqs = "select distinct species as species from iris")
)
## use include_params to review the execution context
run_queries(
c(top_n = "select * from iris limit {n}",
uniqs = "select distinct species as species from iris"),
include_params = TRUE
)
## pass an env of interpolation values to the 'values' parameter
## result of a single, unnamed query is returned as an object, not a
## 1-element list
e <- new.env()
e$n <- 2
run_queries(
"select * from iris limit {n}",
values = e
)
## Use the execmethod parameter for statements
run_queries("create table iris_setosa as select * from iris where species = 'setosa'",
execmethod = 'execute')
run_queries("select distinct species as species from iris_setosa")
Run the code above in your browser using DataLab