Database: Database

Description Usage Arguments Details Examples

Description

Represents a database, handling the connections itself. It allows you to perform operations through the use of functions (e.g. list tables, query data).

Usage

1
2
3
4
5
6
credentials <- DatabaseCredentials$new("connection", "user", "password")
database <- Database$new(credentials)

database$list(tableType)
database$listTableInformation(tableName)
database$query(query)

Arguments

credentials

Object containing all the information required to connect to a database.

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.

tableType

Table type (e.g. TABLE, VIEW)

tableName

Name of the table inside a database.

query

SQL query to run against the database.

Details

$new(databaseCredentials = NULL) Creates an instance of Database.

$list(tableType = "TABLE") List all the tables (name and description) in the database according to the type given.

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

$query(query = NuLL) Queries the database when given a valid SQL Query (e.g. SELECT * FROM table)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
# Building the Database object.
dsn <- "connection"
uid <- "root"
pwd <- "password"

databaseCredentials <- DatabaseCredentials$new(dsn, uid, pwd)
database <- Database$new(databaseCredentials)

# Listing all the tables and views in the database.
database$list("TABLE")
database$list("VIEW")

# List information about a sepecif table.
database$listTableInformation("tableName")

# Query the database to get information.
database$query("SELECT * FROM table")

## End(Not run)

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