Implementation of the DataStorage
R6 class to SQLite backend using a unified
API for read/write operations
Super classes
shiny.telemetry::DataStorage
-> shiny.telemetry::DataStorageSQLFamily
-> DataStorageSQLite
Methods
Method new()
Initialize the data storage class
Usage
DataStorageSQLite$new(db_path = "user_stats.sqlite")
Examples
db_path <- tempfile(fileext = ".sqlite")
data_storage <- DataStorageSQLite$new(db_path = db_path)
data_storage$insert("example", "test_event", "session1")
data_storage$insert("example", "input", "s1", list(id = "id1"))
data_storage$insert("example", "input", "s1", list(id = "id2", value = 32))
data_storage$insert(
"example", "test_event_3_days_ago", "session1",
time = lubridate::as_datetime(lubridate::today() - 3)
)
data_storage$read_event_data()
#> # A tibble: 4 × 8
#> time app_name session type id value date username
#> <dttm> <chr> <chr> <chr> <chr> <chr> <date> <chr>
#> 1 2024-10-17 10:47:49 example session1 test_ev… NA NA 2024-10-17 NA
#> 2 2024-10-17 10:47:49 example s1 input id1 NA 2024-10-17 NA
#> 3 2024-10-17 10:47:49 example s1 input id2 32 2024-10-17 NA
#> 4 2024-10-14 00:00:00 example session1 test_ev… NA NA 2024-10-14 NA
data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1)
#> # A tibble: 3 × 8
#> time app_name session type id value date username
#> <dttm> <chr> <chr> <chr> <chr> <chr> <date> <chr>
#> 1 2024-10-17 10:47:49 example session1 test_ev… NA NA 2024-10-17 NA
#> 2 2024-10-17 10:47:49 example s1 input id1 NA 2024-10-17 NA
#> 3 2024-10-17 10:47:49 example s1 input id2 32 2024-10-17 NA
file.remove(db_path)
#> [1] TRUE