Installation of current released version from CRAN
Installation of current development version from GitHub
Create new rocker database handling object
Option 1
Option 2
Terminal output
Controlling terminal output
db <- rocker::newDB(verbose = TRUE) # New database handling object
#> dctr | New object
db$setupPostgreSQL()
#> Dctr | Driver load RPostgres
db$unloadDriver()
#> dctr | Driver unload RPostgres
db$verbose <- TRUE # Terminal output on (default)
db$setupPostgreSQL()
#> Dctr | Driver load RPostgres
db$unloadDriver()
#> dctr | Driver unload RPostgres
Structure of terminal output
Dctr | Driver load RSQLite
D = Driver (D = loaded, d = not set)
c = Connection (C = opened, c = closed)
t = Transation (T = active, t = no tranastion)
r = Result (R = available, r = no result)
Driver load RSQLite = Message text
Optional object ID
Optionally, rocker object can be labeled with an ID. This can be helpful in case terminal output of multiple rocker objects need to be distinguished.
db1 <- rocker::newDB(id = "myDB 1") # New database handling object with ID
#> myDB 1 | dctr | New object id myDB 1
db2 <- rocker::newDB(id = "myDB 2") # New database handling object with ID
#> myDB 2 | dctr | New object id myDB 2
db1$setupPostgreSQL()
#> myDB 1 | Dctr | Driver load RPostgres
db2$setupMariaDB()
#> myDB 2 | Dctr | Driver load RMariaDB
db1$unloadDriver()
#> myDB 1 | dctr | Driver unload RPostgres
db2$unloadDriver()
#> myDB 2 | dctr | Driver unload RMariaDB
db1$id <- NULL # Remove ID
db1$setupSQLite()
#> Dctr | Driver load RSQLite
db1$unloadDriver()
#> dctr | Driver unload RSQLite
db1$id <- "newID 1" # Add new ID
db1$setupSQLite()
#> newID 1 | Dctr | Driver load RSQLite
db1$unloadDriver()
#> newID 1 | dctr | Driver unload RSQLite
Object properties
Object properties are stored in the info field and can be displayed by print function.
db <- rocker::newDB() # New database handling object
#> dctr | New object
db$setupPostgreSQL()
#> Dctr | Driver load RPostgres
db$info
#> $package
#> [1] "RPostgres"
#>
#> $host
#> [1] "127.0.0.1"
#>
#> $port
#> [1] "5432"
#>
#> $dbname
#> [1] "mydb"
db
#> object
#> id null
#> verbose true
#> validateQuery null
#> database
#> package RPostgres
#> host 127.0.0.1
#> port 5432
#> dbname mydb
#> status
#> driver true
#> connection false
#> transaction false
#> result false
db$print()
#> object
#> id null
#> verbose true
#> validateQuery null
#> database
#> package RPostgres
#> host 127.0.0.1
#> port 5432
#> dbname mydb
#> status
#> driver true
#> connection false
#> transaction false
#> result false
print(db)
#> object
#> id null
#> verbose true
#> validateQuery null
#> database
#> package RPostgres
#> host 127.0.0.1
#> port 5432
#> dbname mydb
#> status
#> driver true
#> connection false
#> transaction false
#> result false
Connection validation – Is the earlier opened database connection still open?
db <- rocker::newDB() # New database handling object
#> dctr | New object
db$setupSQLite()
#> Dctr | Driver load RSQLite
db$print()
#> object
#> id null
#> verbose true
#> validateQuery null
#> database
#> package RSQLite
#> dbname :memory:
#> status
#> driver true
#> connection false
#> transaction false
#> result false
During connection setup, a validateQuery is looked up automatically.
db$connect()
#> DCtr | Database connected
db$print()
#> object
#> id null
#> verbose true
#> validateQuery SELECT 1
#> database
#> package RSQLite
#> dbname :memory:
#> status
#> driver true
#> connection true
#> transaction false
#> result false
Discovered validateQuery
Validate connection
If required, validateQuery can be defined manually.
db$validateQuery <- "SELECT 2"
db$validateCon()
#> DCtr | Connection valid true
#> [1] TRUE
db$print()
#> object
#> id null
#> verbose true
#> validateQuery SELECT 2
#> database
#> package RSQLite
#> dbname :memory:
#> status
#> driver true
#> connection true
#> transaction false
#> result false
Clean up