#' Return current session context
#'
#' Queries for context variables related to the current Snowflake session. Examples are ROLE, CLIENT, etc.
#'
#' The boilerplate parts of the base name are added by the function. For example `"region"` will become `CURRENT_REGION()` and `"role"` will become `CURRENT_ROLE()`.
#'
#' @param current_set Optional character vector that contains the base of context variable. When missing all variables are returned.
#' @param con A connection object. Typically generated by [flaky_connect()].
#'
#' @source <https://docs.snowflake.net/manuals/sql-reference/functions-context.html>
#'
#' @export
#'
#' @examples
#' /dontrun{
#' # See all variables
#' flaky_current()
#'
#' # See one variable
#' flaky_current("warehouse")
#'
#' # See a few variables
#' flaky_current(c("role", "schema"))
#' }
flaky_current <- function(current_set, con = getOption("flaky.con")) {
cur_opts <- c(
"account",
"client",
"database",
"date",
"region",
"role",
"schema",
"session",
"time",
"timestamp",
"version",
"user",
"warehouse"
)
if (!missing(current_set)) cur_opts <- intersect(tolower(current_set), cur_opts)
query <- paste("SELECT", paste("current_", cur_opts, "()", sep = "", collapse = ", "))
dplyr::tbl(con, dbplyr::sql(query)) %>%
dplyr::rename_all(~stringr::str_remove(., '\\(\\)'))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.