R/list.R

Defines functions docdb_list.src_duckdb docdb_list.src_postgres docdb_list.src_sqlite docdb_list.src_mongo docdb_list.src_elastic docdb_list.src_couchdb docdb_list

Documented in docdb_list

#' List containers in database
#'
#' @inheritParams docdb_create
#'
#' @param ... Passed to function [DBI::dbListTables()]
#'
#' @return (vector) Names of containers that can be
#' used as parameter `key` with other functions such as
#' [docdb_create()].
#'
#' @export
#'
#' @examples \dontrun{
#' src <- src_sqlite()
#' docdb_create(src, "iris", iris)
#' docdb_list(src)
#' }
docdb_list <- function(src, ...) {
  assert(src, "docdb_src")
  UseMethod("docdb_list", src)
}

#' @export
docdb_list.src_couchdb <- function(src, ...) {

  result <- sofa::db_list(src$con)
  result <- result[result != "_users"]
  return(result)

}

#' @export
docdb_list.src_elastic <- function(src, ...) {

  result <- elastic::aliases_get(src$con)
  result <- names(result)
  return(result)

}

#' @export
docdb_list.src_mongo <- function(src, ...) {

  result <- src$con$run(
    command = '{"listCollections":1}',
    simplify = TRUE)

  result <- unlist(result, use.names = TRUE)
  result <- result[grepl("atch[.]name[0-9]*$", names(result))]
  result <- result[result != "system.indexes"]
  result <- unname(result)

  return(result)
}

#' @export
docdb_list.src_sqlite <- function(src, ...) {
  return(DBI::dbListTables(src$con, ...))
}

#' @export
docdb_list.src_postgres <- function(src, ...) {
  return(DBI::dbListTables(src$con, ...))
}

#' @export
docdb_list.src_duckdb <- function(src, ...) {
  return(DBI::dbListTables(src$con, ...))
}

Try the nodbi package in your browser

Any scripts or data that you put into this service are public.

nodbi documentation built on Sept. 30, 2024, 1:06 a.m.