sqlDao: A Data Access Object (DAO) that uses the DBI interface to...

Description Usage Arguments Details Value See Also Examples

View source: R/sqlDao.R

Description

DAO is a list that provides basic backend CRUD functionality to the crudTableServer. This DAO uses DBI to store the data. The DBI table accessed with this DAO object must not contain the 'id' attribute, as it is internally created from the DBI's 'rowid' attribute.

Usage

1

Arguments

con

A DBI connection

table

A character string of the name of the table to be accessed

typecast

A named list of typecast objects. If non-empty, the elements of this list must correspond to the attributes of the SQL data table. A conversion between internal and output data types is then performed on data insert, update or retrieval.

Details

See dataFrameDao for more details on Data Access Objects.

Since the DBI interface typically converts various complex R data types (such as Date) into atomic types such as number, character string and so on, sqlDao may optionally convert the data for you into a more convenient format – see the typecast argument.

Value

A DAO object, i.e. a list of functions for CRUD operations on the DBI table as neeeded by the crudTableServer module

See Also

dataFrameDao, is.dao, typecast

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
library(DBI)
library(RSQLite)

# Create an in-memory database
con <- dbConnect(RSQLite::SQLite(), ":memory:")

# Create an empty data table
data <- data.frame(date = character(0), value = numeric(0))
dbWriteTable(con, 'mytable', data)

# Create Data Access Object - the date attribute will be internally stored as character
# but transparently returned as 'Date' by the DAO
dao <- sqlDao(con,
              table = 'mytable',
              typecast = list(date = typecastDateToCharacter()))

# Insert data record
dao$insert(list(date = Sys.Date(), value = 100))

# Print data table
print(dao$getData())

# Disconnect from the database
dbDisconnect(con)

beerda/crudtable documentation built on July 13, 2020, 2:16 p.m.