ThinkR-open / bank

Alternative caching backends for `{memoise}` & `{shiny}`.
Other
12 stars 2 forks source link

Easier SQL backends #11

Closed ggpinto closed 1 year ago

ggpinto commented 2 years ago

Here I changed cache_postgres to facilitate new SQL backends, what I have done is:

cache_ms_sql <- R6::R6Class(
  "cache_ms_sql",
  inherit = cache_postgres,
  public = list(
    #' @description
    #' Start a new Microsoft SQL Server cache
    #' @param ... Parameters passes do DBI::dbConnect(odbc::odbc(), ...)
    #' @param cache_table On `initialize()`, the cache object will create a table
    #' to store the cache. Default name is `bankrcache`. Change it if you already
    #' have a table named `bankrcache` in your DB.
    #' @param algo for `{memoise}` compatibility, the `digest()` algorithm
    #' @param compress for `{memoise}` compatibility, should the data be compressed?
    #' @return A cache_ms_sql object
    initialize = function(...,
                          cache_table = "bankrcache",
                          algo = "sha512",
                          compress = FALSE) {

      private$check_dependencies("cache_ms_sql", "odbc")

      private$interface <- private$connect(odbc::odbc(), ...)

      private$sql_column_data = list(
            column_id = list(type = "varchar(max)", type_description = "varchar"),
            column_cache = list(type = "varbinary(max)", type_description = "varbinary")

      private$cache_table <- cache_table

      private$check_table()

      private$algo <- algo

      private$compress <- compress
    }
  )
)
ColinFay commented 2 years ago

Hey @ggpinto,

thanks for that. I'm on holidays rn so i'll have a look into that next week :)