| spsDb | R Documentation |
Initiate this container at global level. Methods in this class can help admin to manage general information of SPS. For now it stores some meta data, the encryption key pairs and the account info. You can use this database to store other useful things, like user password hash, IP, browsing info ...
A SQLite database by default is created inside config directory.
If not, you
can use createDb method to create one. On initiation, this class checks
if the default db is there and gives warnings if not.
One instance of this class is created by the spsAccount super class in global.R, normal users don't need to change anything.
new()initialize a new class object
spsDb$new()
createDb()Create a SPS database
spsDb$createDb(db_name = "config/sps.db")
db_namedatabase path, you need to manually create parent directory if not exists
queryValue()Query database
spsDb$queryValue(table, SELECT = "*", WHERE = "1", db_name = "config/sps.db")
tabletable name
SELECTSQL select grammar
WHERESQL where grammar
db_namedatabase path
query result, usually a dataframe
queryValueDp()Query database with dplyr grammar
Only supports simple selections, like comparison, %in%, between(),
is.na(), etc. Advanced selections like wildcard,
using outside dplyr functions like [stringr::str_detect()],
[base::grepl()] are not supported.
spsDb$queryValueDp( table, dp_expr = "select(., everything())", db_name = "config/sps.db" )
tabletable name
dp_exprdplyr chained expression, must use '.' in first component of the chain expression
db_namedatabase path
query result, usually a tibble
queryUpdate()update(modify) the value in db
spsDb$queryUpdate(table, value, col, WHERE = "1", db_name = "config/sps.db")
tabletable name
valuenew value
colwhich column
WHERESQL where statement, conditions to select rows
db_namedatabase path
queryDel()delete value in db
spsDb$queryDel(table, WHERE = "1", db_name = "config/sps.db")
tabletable name
WHERESQL where statement, conditions to select rows
db_namedatabase path
queryInsert()Insert value to db
spsDb$queryInsert(table, value, db_name = "config/sps.db")
tabletable name
valuenew values for the entire row, collect all values from all columns in a vector.
db_namedatabase path
clone()The objects of this class are cloneable with this method.
spsDb$clone(deep = FALSE)
deepWhether to make a deep clone.
dir.create("config", showWarnings = FALSE)
mydb <- spsDb$new()
mydb$createDb()
mydb$queryValue("sps_meta")
mydb$queryInsert("sps_meta", value = "'new1', '1'")
mydb$queryValue("sps_meta")
mydb$queryInsert("sps_meta", value = c("'new2'", "'2'"))
mydb$queryValue("sps_meta")
mydb$queryUpdate("sps_meta", value = '234',
col = "value", WHERE = "info = 'new1'")
mydb$queryValue("sps_meta")
## Not run:
library(dplyr)
mydb$queryValueDp(
"sps_meta",
dp_expr="filter(., info %in% c('new1', 'new2') %>% select(2)")
## End(Not run)
mydb$queryDel("sps_meta", WHERE = "value = '234'")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.