Skip to content

Commit

Permalink
Merge pull request #326 from r-dbi/f-inline-bind
Browse files Browse the repository at this point in the history
feat: Inline all tests for `dbBind()`
  • Loading branch information
aviator-app[bot] authored Dec 17, 2023
2 parents 48f959d + 7ab5cf0 commit 6f747e5
Show file tree
Hide file tree
Showing 6 changed files with 1,069 additions and 503 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Depends:
Imports:
blob (>= 1.2.0),
callr,
constructive,
DBI (>= 1.1.3.9004),
desc,
hms (>= 0.5.0),
Expand All @@ -34,6 +33,7 @@ Imports:
withr
Suggests:
clipr,
constructive,
dblog (>= 0.0.0.9008),
debugme,
devtools,
Expand Down
54 changes: 41 additions & 13 deletions R/spec-meta-bind-.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,54 @@
# Helpers -----------------------------------------------------------------

test_select_bind <- function(
con,
ctx,
test_select_bind_expr <- function(
bind_values,
ctx = stop("ctx is available during run time only"),
...,
cast_fun = identity,
query = TRUE,
skip_fun = NULL,
cast_fun = NULL,
requires_names = NULL) {

force(bind_values)
test_expr <- run_bind_tester$fun(bind_values = bind_values, ...)

placeholder_funs <- get_placeholder_funs(ctx, requires_names)
cast_fun <- rlang::enquo(cast_fun)
has_cast_fun <- !rlang::quo_is_null(cast_fun)
cast_fun_expr <- if (has_cast_fun) rlang::expr({
cast_fun <- !!rlang::quo_get_expr(cast_fun)
})

test_expr <- test_select_bind_expr_one$fun(
bind_values = bind_values,
...,
query = query,
has_cast_fun = has_cast_fun
)

force(con)
is_null_check <- ctx$tweaks$is_null_check
force(cast_fun)
allow_na_rows_affected <- ctx$tweaks$allow_na_rows_affected
skip_expr <- if (!is.null(skip_fun)) rlang::expr({
skip_if(!!body(skip_fun))
})

for (placeholder_fun in placeholder_funs) {
rlang::eval_bare(test_expr)
if (is.null(requires_names)) {
placeholder_funs_expr <- rlang::expr(get_placeholder_funs(ctx))
} else {
placeholder_funs_expr <- rlang::expr(get_placeholder_funs(ctx, requires_names = !!requires_names))
}

allow_na_rows_affected_expr <- if (!query) rlang::expr({
allow_na_rows_affected <- ctx$tweaks$allow_na_rows_affected
})

rlang::expr({
!!skip_expr
placeholder_funs <- !!placeholder_funs_expr

is_null_check <- ctx$tweaks$is_null_check
!!cast_fun_expr
!!allow_na_rows_affected_expr

for (placeholder_fun in placeholder_funs) {
!!test_expr
}
})
}

get_placeholder_funs <- function(ctx, requires_names = NULL) {
Expand Down
Loading

0 comments on commit 6f747e5

Please sign in to comment.