DBCon: R6 Class for connecting to a database.

DBConR Documentation

R6 Class for connecting to a database.

Description

R6 class for for connecting to your OFPE database. The default database driver is PostgreSQL as that is recommended for OFPE use and shown in the OFPE tutorials and vignettes. However, any database driver can be supplied. This class was created to consolidate database connections being supplied to functions and other R6 classes in the OFPE data workflow.

Users can connect with any DBI compliant option. Using RPostgreSQL drivers on a Mac, users can provide the user, password, dbname, host, and port. If on a Windows computer the user just needs to set up a PostgreSQL ODBC driver, and supply the DSN, user, and password.

Public fields

db

Database connection, such as PostgreSQL connection.

Methods

Public methods


Method new()

Create a database connection inside of the DBCon class.

Usage
DBCon$new(
  user = NA,
  password = NA,
  dbname = NULL,
  host = NULL,
  port = NULL,
  dsn = NULL
)
Arguments
user

Username associated with the database owner.

password

Password associated with the database owner.

dbname

Name of the database to connect to.

host

Host name of the database location (typically localhost) unless user is connecting to a non-local database.

port

The port number of the database.

dsn

Optional. If ODBC database source name is setup. Required for Windows users.

Returns

An open database connection.


Method disconnect()

Close a database connection in the DCCon class.

Usage
DBCon$disconnect()
Arguments
None

No parameters necessary. Simply call the method.

Returns

A closed database connection.


Method clone()

The objects of this class are cloneable with this method.

Usage
DBCon$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


paulhegedus/OFPE documentation built on Nov. 23, 2022, 5:09 a.m.