File: DBIConnector.R

package info (click to toggle)
dbi 1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,004 kB
  • sloc: makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,558 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
NULL

#' DBIConnector class
#'
#' Wraps objects of the [DBIDriver-class] class to include connection options.
#' The purpose of this class is to store both the driver
#' and the connection options.
#' A database connection can be established
#' with a call to [dbConnect()], passing only that object
#' without additional arguments.
#'
#' To prevent leakage of passwords and other credentials,
#' this class supports delayed evaluation.
#' All arguments can optionally be a function (callable without arguments).
#' In such a case, the function is evaluated transparently when connecting in
#' [dbGetConnectArgs()].
#'
# FIXME: Include this
# Database backends can take advantage of this feature by returning an
# instance of this class instead of `DBIDriver`.
# See the implementation of [RSQLite::SQLite()]  for an example.
#'
#' @docType class
#' @name DBIConnector-class
#' @family DBI classes
#' @family DBIConnector generics
#' @export
#' @examplesIf requireNamespace("RSQLite", quietly = TRUE)
#' # Create a connector:
#' cnr <- new("DBIConnector",
#'   .drv = RSQLite::SQLite(),
#'   .conn_args = list(dbname = ":memory:")
#' )
#' cnr
#'
#' # Establish a connection through this connector:
#' con <- dbConnect(cnr)
#' con
#'
#' # Access the database through this connection:
#' dbGetQuery(con, "SELECT 1 AS a")
#' dbDisconnect(con)
setClass("DBIConnector",
  slots = c(".drv" = "DBIDriver", ".conn_args" = "list"),
  contains = c("DBIObject")
)

names2 <- function(x) {
  if (is.null(names(x))) {
    rep("", length(x))
  } else {
    names(x)
  }
}