Database: Class '"Database"'

Description Objects from the Class Slots Methods Author(s) See Also Examples

Description

An object representing an SQLite database containing both the location of the file as well as a TableSchemaList object describing the structure of the database.

Objects from the Class

Objects can be created by calls of the form Database(tbsl, db.file).

Slots

tbsl:

Object of class "TableSchemaList" representing the current or desired database schema

db.file:

Single file path to the desired location of the database

connection:

An object of class "SQLiteConnection"

Methods

isOpen

signature(obj = "Database"): Return a logical value indicating if the database connection is open

columns

signature(obj = "Database"): Returns a list of the database table columns indexed by table name

dbFile

signature(obj = "Database"): Returns the file path associated with the database

populate

signature(obj = "Database"), ..., use.tables = NULL, should.debug = FALSE: Populate an SQLite database using the schema and location from the Database object and the data to be inserted as specified in the dta.func element of the TableSchemaList. The use.tables argument can be used to limit the tables populated. The should.debug argument outputs more verbose messages regarding the SQL queries.

schema

signature(obj = "Database"): Returns the associated TableSchemaList object

tables

signature(obj = "Database"): Returns a character vector containing the table names

Author(s)

Daniel Bottomly

See Also

TableSchemaList

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
if (require(Lahman) && require(RSQLite))
{
 baseball.teams <- makeSchemaFromData(TeamsFranchises, name="team_franch")
 baseball.teams <- append(baseball.teams, makeSchemaFromData(Teams, name="teams"))
 
 relationship(baseball.teams, from="team_franch", to="teams") <- franchID ~ franchID
 
 baseball.db <- Database(baseball.teams, tempfile())
 
 tables(baseball.db)
 columns(baseball.db)
 schema(baseball.db)
 
 populate(baseball.db, teams=Teams, team_franch=TeamsFranchises)
 
 examp.con <- dbConnect(SQLite(), dbFile(baseball.db))
 
 dbListTables(examp.con)
 
 head(dbReadTable(examp.con, "teams"))
 head(dbReadTable(examp.con, "team_franch"))
 
 dbDisconnect(examp.con)
 
}

poplite documentation built on May 14, 2019, 1:02 a.m.