R/describeRegistryDb.R

Defines functions describeRegistryDb

Documented in describeRegistryDb

#' Provide registry daatabase metadata
#'
#' List all tables and fields with attributes such as type and degault values
#'
#' @param registryName String providing the registry name key
#' @param tabs Character vector for optional definition of tables to describe.
#' Defaults to an empty vector in which case all tables are used
#'
#' @return A list with table names and corresponding fields with attributes
#' @export

describeRegistryDb <- function(registryName, tabs = c()) {

  qGetTabs <- "SHOW TABLES;"
  qGetDesc <- "DESCRIBE "

  desc <- list()

  if (length(tabs) == 0) {
    tabs <- rapbase::loadRegData(registryName = registryName,
                                 query = qGetTabs)[[1]]
  }

  for (tab in tabs) {
    query <- paste0(qGetDesc, tab, ";")
    desc[[tab]] <- rapbase::loadRegData(registryName, query)
  }

  desc
}
Rapporteket/NORIC documentation built on Feb. 15, 2024, 5:25 p.m.