Author: Nikolaus Pawlowski

# Usage of S3 class functions on R6 rocker class

#### Nikolaus Pawlowski

# Usage of S3 and R6 functions

Although rocker is a R6 class, functions can be also accesses in classical S3 way.

S3 example

    library(rocker)
    db <- newDB()
    #> dctr | New object
    setupDriver(db, drv = RSQLite::SQLite(), dbname = ":memory:")
    #> Dctr | Driver load RSQLite
    connect(db)
    #> DCtr | Database connected
    writeTable(db, "mtcars", mtcars)
    #> DCtr | Write table mtcars columns mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb rows 32
    sendQuery(db, "SELECT * FROM mtcars;")
    #> DCtR | Send query 21 characters
    output <- fetch(db)
    #> DCtR | Fetch rows all -> Received 32 rows, 11 columns, 4824 bytes
    clearResult(db)
    #> DCtr | Clear result
    disconnect(db)
    #> Dctr | Database disconnected
    unloadDriver(db)
    #> dctr | Driver unload RSQLite

R6 example

    db <- rocker::newDB()
    #> dctr | New object
    db$setupDriver(drv = RSQLite::SQLite(), dbname = ":memory:")
    #> Dctr | Driver load RSQLite
    db$connect()
    #> DCtr | Database connected
    db$writeTable("mtcars", mtcars)
    #> DCtr | Write table mtcars columns mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb rows 32
    db$sendQuery("SELECT * FROM mtcars;")
    #> DCtR | Send query 21 characters
    output <- db$fetch()
    #> DCtR | Fetch rows all -> Received 32 rows, 11 columns, 4824 bytes
    db$clearResult()
    #> DCtr | Clear result
    db$disconnect()
    #> Dctr | Database disconnected
    db$unloadDriver()
    #> dctr | Driver unload RSQLite