#' Query a specific table in the Postgres database containing the metadata #' @param table Table name. See [list_metadata_tables()] for valid tables. #' @importFrom DBI dbConnect dbGetQuery #' @importFrom RPostgres Postgres #' @importFrom dplyr tbl #' @export query_metadata_table <- function(table = "single_builds") { con <- DBI::dbConnect(RPostgres::Postgres(), dbname = "build_metadata", host = "r-binaries.devxy.io", port = 15432, user = "r_binaries", password = Sys.getenv("PGPASS") ) metadata <- tbl(con, table) return(metadata) } #' List existing database tables #' @export list_metadata_tables <- function() { con <- DBI::dbConnect(RPostgres::Postgres(), dbname = "build_metadata", host = "r-binaries.devxy.io", port = 15432, user = "r_binaries", password = Sys.getenv("PGPASS") ) dbListTables(con) } query_metadata_summary <- function(package_name = NULL, platform = NULL) { # s3 <- paws.storage::s3(config = list( # endpoint = "https://s3.eu-central-003.backblazeb2.com", # region = "eu-central-003" # )) # db_local <- s3$get_object(Bucket = "devxy-arm64-r-binaries-db", Key = "metadata.sqlite") # writeBin(db_local$Body, "/tmp/metadata.sqlite") # Create a new SQLite connection con <- dbcon_mem() # If both package_name and platform are NULL, return the full table if (is.null(package_name) && is.null(platform)) { summary <- dbGetQuery(con, "SELECT * FROM metadata_summary") } else { # Query the metadata_summary table for the specified package and platform summary <- dbGetQuery(con, paste0( "SELECT * FROM metadata_summary WHERE package_name = '", package_name, "' AND platform = '", platform, "'" )) } # Close the SQLite connection dbDisconnect(con) return(summary) }