DBIConnector-class: DBIConnector class

Description Details See Also Examples

Description

Wraps objects of the DBIDriver 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.

Details

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().

See Also

Other DBI classes: DBIConnection-class, DBIDriver-class, DBIObject-class, DBIResult-class

Other DBIConnector generics: dbConnect(), dbDataType(), dbGetConnectArgs(), dbIsReadOnly()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 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)

Example output

<DBIConnector><SQLiteDriver>
Arguments:
$dbname
[1] ":memory:"

<SQLiteConnection>
  Path: :memory:
  Extensions: TRUE
  a
1 1

DBI documentation built on Jan. 15, 2021, 3:29 p.m.