R/db_version.R

Defines functions db_version

Documented in db_version

#' Function to get the version of a database service.
#' 
#' @author Stuart K. Grange
#' 
#' @param con Database connection. 
#' 
#' @return Character vector
#' 
#' @export
db_version <- function(con) {
  
  if (db.class(con) == "sqlite") {
    x <- db_get(con, "SELECT sqlite_version()")[, 1]
  } else if (db.class(con) %in% c("mysql", "mariadb")) {
    stop("Not implemented.", call. = FALSE)
  } else if (db.class(con) == "postgres") {
    x <- db_get(con, "SELECT version()")[, 1, drop = TRUE]
  } else {
    stop("Database connection not supported.", call. = FALSE)
  }
    
  return(x)
  
}
skgrange/databaser documentation built on Sept. 13, 2024, 3:53 a.m.