Installation of current released version from CRAN
install.packages("rocker")Installation of current development version from GitHub
install.packages("devtools")
devtools::install_github("nikolaus77/rocker")Create new rocker database handling object
Option 1
db <- rocker::newDB() # New database handling object
#> dctr | New objectOption 2
db <- rocker::rocker$new() # New database handling object
#> dctr | New objectTerminal 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 RPostgresdb$verbose <- FALSE # Terminal output off
db$setupPostgreSQL()
db$unloadDriver()db$verbose <- TRUE # Terminal output on (default)
db$setupPostgreSQL()
#> Dctr | Driver load RPostgres
db$unloadDriver()
#> dctr | Driver unload RPostgresStructure 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 RMariaDBdb1$id <- NULL # Remove ID
db1$setupSQLite()
#> Dctr | Driver load RSQLite
db1$unloadDriver()
#> dctr | Driver unload RSQLitedb1$id <- "newID 1" # Add new ID
db1$setupSQLite()
#> newID 1 | Dctr | Driver load RSQLite
db1$unloadDriver()
#> newID 1 | dctr | Driver unload RSQLiteObject 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 falsedb$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 falseprint(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 falsedb$unloadDriver()
#> dctr | Driver unload RPostgresConnection 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 falseDuring 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 falseDiscovered validateQuery
db$validateQuery
#> [1] "SELECT 1"Validate connection
db$validateCon()
#> DCtr | Connection valid true
#> [1] TRUEIf 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 falseClean up
db$disconnect()
#> Dctr | Database disconnected
db$validateCon()
#> Dctr | Connection valid false
#> [1] FALSE
db$unloadDriver()
#> dctr | Driver unload RSQLite