queries: SQL Query Objects

QueryR Documentation

SQL Query Objects

Description

Data types to represent SQL queries. It should not be necessary to use SingleQuery and SingleQueryList interactively. Query is the generic user interface to generate SQL queries and is based on text parsing.

Usage

Query(
  .x,
  ...,
  .data = NULL,
  .envir = parent.frame(),
  checkSemicolon = TRUE,
  keepComments = FALSE
)

Arguments

.x

(character | connection) A character or connection containing a query.

...

Parameters to be substituted in .x

.data

(list)

.envir

(environment) Should be left with the default. Sets the environment in which to evaluate code chunks in queries.

checkSemicolon

(logical) Should be left with the default. Set to false only in case you want to allow for semicolons within the query.

keepComments

(logical) In most cases it is safe(er) to remove comments from a query. When you want to keep them set the argument to TRUE. This only applies when .x is a file.

Details

SingleQuery inherits from character and represents a single query.

SingleQueryList inherits from list and represents a list of single queries. It can be constructed with a list of character values.

Examples

query1 <- "SELECT {{ varName }} FROM {{ tableName }} WHERE primaryKey = {{ id }};"
query2 <- "SHOW TABLES;"

Query(query1, varName = "someVar", tableName = "someTable", .data = list(id = 1:2))

tmpFile <- tempfile()
writeLines(c(query1, query2), tmpFile)
Query(file(tmpFile))

INWT/dbtools documentation built on Aug. 21, 2022, 9:37 p.m.