Class for handling DatabaseConnector:connection objects with consistent R6 interfaces for pooled and non-pooled connections. Allows a connection to cleanly be opened and closed and stored within class/object variables

Value

DatabaseConnector Connection instance close Connection

boolean TRUE if connection is valid queryDb

boolean TRUE if connection is valid executeSql

Public fields

connectionDetails

DatabaseConnector connectionDetails object

con

DatabaseConnector connection object

isActive

Is connection active or not#'

snakeCaseToCamelCase

(Optional) Boolean. return the results columns in camel case (default)

Methods


Method new()

Usage

ConnectionHandler$new(
  connectionDetails,
  loadConnection = TRUE,
  snakeCaseToCamelCase = TRUE
)

Arguments

connectionDetails

DatabaseConnector::connectionDetails class

loadConnection

Boolean option to load connection right away

snakeCaseToCamelCase

(Optional) Boolean. return the results columns in camel case (default) get dbms


Method dbms()

Get the dbms type of the connection get table

Usage

ConnectionHandler$dbms()


Method tbl()

get a dplyr table object (i.e. lazy loaded)

Usage

ConnectionHandler$tbl(table, databaseSchema = NULL)

Arguments

table

table name

databaseSchema

databaseSchema to which table belongs Render Translate Sql.


Method renderTranslateSql()

Masked call to SqlRender

Usage

ConnectionHandler$renderTranslateSql(sql, ...)

Arguments

sql

Sql query string

...

Elipsis initConnection


Method initConnection()

Load connection Get Connection

Usage

ConnectionHandler$initConnection()


Method getConnection()

Returns connection for use with standard DatabaseConnector calls. Connects automatically if it isn't yet loaded

Usage

ConnectionHandler$getConnection()


Method closeConnection()

Closes connection (if active) close Connection

Usage

ConnectionHandler$closeConnection()


Method finalize()

Closes connection (if active) db Is Valid

Usage

ConnectionHandler$finalize()


Method dbIsValid()

Masks call to DBI::dbIsValid. Returns False if connection is NULL

Usage

ConnectionHandler$dbIsValid()


Method queryDb()

query database and return the resulting data.frame

If environment variable LIMIT_ROW_COUNT is set Returned rows are limited to this value (no default) Limit row count is intended for web applications that may cause a denial of service if they consume too many resources.

Usage

ConnectionHandler$queryDb(
  sql,
  snakeCaseToCamelCase = self$snakeCaseToCamelCase,
  overrideRowLimit = FALSE,
  ...
)

Arguments

sql

sql query string

snakeCaseToCamelCase

(Optional) Boolean. return the results columns in camel case (default)

overrideRowLimit

(Optional) Boolean. In some cases, where row limit is enforced on the system You may wish to ignore it.

...

Additional query parameters


Method executeSql()

execute set of database queries

Usage

ConnectionHandler$executeSql(sql, ...)

Arguments

sql

sql query string

...

Additional query parameters query Function


Method queryFunction()

queryFunction that can be overriden with subclasses (e.g. use different base function or intercept query) Does not translate or render sql.

Usage

ConnectionHandler$queryFunction(
  sql,
  snakeCaseToCamelCase = self$snakeCaseToCamelCase,
  connection = self$getConnection()
)

Arguments

sql

sql query string

snakeCaseToCamelCase

(Optional) Boolean. return the results columns in camel case (default)

connection

(Optional) connection object execute Function


Method executeFunction()

exec query Function that can be overriden with subclasses (e.g. use different base function or intercept query) Does not translate or render sql.

Usage

ConnectionHandler$executeFunction(sql, connection = self$getConnection())

Arguments

sql

sql query string

connection

connection object


Method clone()

The objects of this class are cloneable with this method.

Usage

ConnectionHandler$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.