Skip to contents

Implementation of the DataStorage R6 class to SQLite backend using a unified API for read/write operations

Methods

Inherited methods


Method new()

Initialize the data storage class

Usage

DataStorageSQLite$new(db_path = "user_stats.sqlite")

Arguments

db_path

string with path to sqlfile


Method clone()

The objects of this class are cloneable with this method.

Usage

DataStorageSQLite$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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-11-17 13:00:27 example  session1 test_ev… NA    NA    4657030-1… NA      
#> 2 2023-11-17 13:00:27 example  s1       input    id1   NA    4657030-1… NA      
#> 3 2023-11-17 13:00:27 example  s1       input    id2   32    4657030-1… NA      
#> 4 2023-11-14 00:00:00 example  session1 test_ev… NA    NA    4656192-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-11-17 13:00:27 example  session1 test_ev… NA    NA    4657030-1… NA      
#> 2 2023-11-17 13:00:27 example  s1       input    id1   NA    4657030-1… NA      
#> 3 2023-11-17 13:00:27 example  s1       input    id2   32    4657030-1… NA      

file.remove(db_path)
#> [1] TRUE