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 2023-09-13 09:56:24 example session1 test_ev… NA NA 4641624-0… NA
#> 2 2023-09-13 09:56:24 example s1 input id1 NA 4641624-0… NA
#> 3 2023-09-13 09:56:24 example s1 input id2 32 4641624-0… NA
#> 4 2023-09-10 00:00:00 example session1 test_ev… NA NA 4640816-1… 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 2023-09-13 09:56:24 example session1 test_ev… NA NA 4641624-0… NA
#> 2 2023-09-13 09:56:24 example s1 input id1 NA 4641624-0… NA
#> 3 2023-09-13 09:56:24 example s1 input id2 32 4641624-0… NA
file.remove(db_path)
#> [1] TRUE