Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New duck_exec(), replaces duckplyr_execute() #404

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export(df_from_parquet)
export(df_to_parquet)
export(distinct)
export(duck_csv)
export(duck_exec)
export(duck_file)
export(duck_json)
export(duck_parquet)
Expand Down
6 changes: 6 additions & 0 deletions R/duckplyr_execute.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#' Execute a statement for the default connection
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' The \pkg{duckplyr} package relies on a DBI connection
#' to an in-memory database.
#' The `duckplyr_execute()` function allows running SQL statements
Expand All @@ -10,10 +13,13 @@
#'
#' @param sql The statement to run.
#' @return The return value of the [DBI::dbExecute()] call, invisibly.
#' @keywords internal
#' @export
#' @examples
#' duckplyr_execute("SET threads TO 2")
duckplyr_execute <- function(sql) {
lifecycle::deprecate_soft("1.0.0", "duckplyr_execute()", "duck_exec()")

con <- get_default_duckdb_connection()
invisible(DBI::dbExecute(con, sql))
}
31 changes: 31 additions & 0 deletions R/exec.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' Execute a statement for the default connection
#'
#' The \pkg{duckplyr} package relies on a DBI connection
#' to an in-memory database.
#' The `duck_exec()` function allows running SQL statements
#' with this connection to, e.g., set up credentials
#' or attach other databases.
#' See <https://duckdb.org/docs/configuration/overview.html>
#' for more information on the configuration options.
#'
#' @seealso [duck_sql()]
#'
#' @param sql The statement to run.
#' @inheritParams duck_sql
#' @return The return value of the [DBI::dbExecute()] call, invisibly.
#' @export
#' @examples
#' duck_exec("SET threads TO 2")
duck_exec <- function(sql, ..., con = NULL) {
check_dots_empty()

if (!is_string(sql)) {
cli::cli_abort("{.arg sql} must be a string.")
}

if (is.null(con)) {
con <- get_default_duckdb_connection()
}

invisible(DBI::dbExecute(con, sql))
}
4 changes: 2 additions & 2 deletions R/io2.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ duck_csv <- function(path, ..., lazy = TRUE, options = list()) {
#' writeLines('[{"a": 1, "b": "x"}, {"a": 2, "b": "y"}]', path)
#'
#' # Reading needs the json extension
#' duckplyr_execute("INSTALL json")
#' duckplyr_execute("LOAD json")
#' duck_exec("INSTALL json")
#' duck_exec("LOAD json")
#' duck_json(path)
duck_json <- function(path, ..., lazy = TRUE, options = list()) {
check_dots_empty()
Expand Down
2 changes: 2 additions & 0 deletions R/sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#' Using data frames from the calling environment is not supported yet,
#' see <https://github.com/duckdb/duckdb-r/issues/645> for details.
#'
#' @seealso [duck_exec()]
#'
#' @inheritParams duck_file
#' @param sql The SQL to run.
#' @param con The connection, defaults to the default connection.
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ reference:
- fallback
- stats_show
- last_rel
- duckplyr_execute
- duck_exec

- title: Relational operations and expressions
contents:
Expand Down
33 changes: 33 additions & 0 deletions man/duck_exec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/duck_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/duck_sql.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/duckplyr_execute.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading