R/ops-execute.R

Defines functions execute.tbl_db execute

Documented in execute execute.tbl_db

#' @title
#' Execute an expression in the database
#'
#' @param object    (obj) to act upon and execute
#' @param statement (str) command to execute
#' @param ...       (arg) extra arguments
#'
#' @family Database Operations
#' @export
execute <- function(object, statement, ...) {

  UseMethod("execute")

}

#' @rdname execute
#' @param .envir (env) bases of the interpolation (calling environment)
#' @export
execute.tbl_db <- function(object, statement, ..., .envir = parent.frame()) {

  assert_tbl_db(object)
  dbExecute(
    get_tbl_db_conn(object),
    glue_data_sql(
      list(.table = get_tbl_db_from(object)),
      statement,
      .con = get_tbl_db_conn(object),
      .envir = .envir
    ),
    ...
  )

}
tjpalanca/dbtools documentation built on Oct. 7, 2021, 6:43 a.m.