DBAbstractR: DBAbstractR

Description Usage Arguments Details Examples

Description

Represents the abstraction layer between the user and the database. This object encapsulates both a database and an SQL query builder, allowing the extraction of information by simply calling functions. The only requirement is that the user knows what a relational database is and how tables reference each other when related.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
dbAbstractR <- DBAbstractR$new()

dbAbstractR$connectToDatabase(TESTDSN)
# Every command below requires that the connection is established first.
dbAbstractR$listTables()
dbAbstractR$listTableInformation(tableName)
dbAbstractR$createView(viewName, tableMap, distinct, where, groupBy, having)
dbAbstractR$listViews()
dbAbstractR$deleteView(viewName)
dbAbstractR$createDataset(tableMap, distinct, where, groupBy, having)

Arguments

dataSourceName

Data structure normally used to describe the connection to a database.

userID

Id of the user, usually necessary to perform database connections.

password

Password of the user, usually necessary to perform database connections.

tableName

Name of the table inside a database.

viewName

Name of the view inside a database.

tableMap

Dataframe specifing which tables and columns should be used to extract information.

distinct

Logical that dictates if the data retrieved should be distinct or not.

where

Filters the results by the specified conditions.

groupBy

Groups the results by the values of one or more columns.

having

Further filters the results, by allowing the use of agreggation functions (e.g. COUNT, SUM, ...)

Details

$new() Creates an instance of DBAbstractR.

$connectToDatabase(dataSourceName = "", userID = "", password = "") Performs the connection to a database, returning its information.

$listTables Returns a dataframe with all the tables (name and description) in the database.

$listTableInformation(tableName = "") Returns a dataframe with the information (names of the columns, their type and nullability) about a given table.

$createView(viewName, tableMap, distinct = FALSE, where = "", groupBy = "", having = "") Creates a View in the database that can be used for further consultations. The contents of the View can be filtered results composed of one or more tables.

$listViews() Lists all the Views in a database.

$deleteView(viewName) Deletes a View from the database.

$createDataset(tableMap, distinct = FALSE, where = "", groupBy = "", having = "") Returns, from the database, the contents of a single table or a set of tables in the form of a dataframe. This results can be filtered or not.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## Not run: 
# Building the DBabstractR object.
dbAbstractR <- DBAbstractR$new()

# Connecting to a database.
dbAbstractR$connectToDatabase("TESTDSN")

## To perform the methods below, database connection is required.
# List all the tables in the database.
dbAbstractR$listTables()

# List all the information about a given table.
dbAbstractR$listTableInformation()

# Create a view from a table or a set of tables in the database.
dbAbstractR$createView(viewName, tableMap, distinct, where, groupBy, having)
---- TODO -----

# List all the views in the database.
dbAbstractR$listViews()

# Delete a view from the database.
dbAbstractR$deleteView(viewName)

# Create a dataset from a table or a set of tables in the database.
Please view the examples provided above in "$createView()", both methods work
the same way, the only difference is that a data frame is returned here. Also
this method can be used to consult Views, aswell as tables.

## End(Not run)

PedroMiguelFMoreira/DBAbstractR documentation built on May 8, 2019, 1:28 a.m.