-
Notifications
You must be signed in to change notification settings - Fork 184
use type checkers in backend-*.R
files
#1556
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
Changes from 9 commits
9756e11
9db267a
baa0377
b277850
9456b38
01dacaa
d174c23
662eafe
04cf071
eef618f
f0e7a0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,7 @@ simulate_mssql <- function(version = "15.0") { | |
conflict = c("error", "ignore"), | ||
returning_cols = NULL, | ||
method = NULL) { | ||
check_string(method, allow_null = TRUE) | ||
method <- method %||% "where_not_exists" | ||
arg_match(method, "where_not_exists", error_arg = "method") | ||
# https://stackoverflow.com/questions/25969/insert-into-values-select-from | ||
|
@@ -177,6 +178,7 @@ simulate_mssql <- function(version = "15.0") { | |
..., | ||
returning_cols = NULL, | ||
method = NULL) { | ||
check_string(method, allow_null = TRUE) | ||
method <- method %||% "merge" | ||
arg_match(method, "merge", error_arg = "method") | ||
|
||
|
@@ -333,6 +335,7 @@ simulate_mssql <- function(version = "15.0") { | |
second = function(x) sql_expr(DATEPART(SECOND, !!x)), | ||
|
||
month = function(x, label = FALSE, abbr = TRUE) { | ||
check_bool(label) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be tempted to move the check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, interesting. I moved that |
||
if (!label) { | ||
sql_expr(DATEPART(MONTH, !!x)) | ||
} else { | ||
|
@@ -342,6 +345,7 @@ simulate_mssql <- function(version = "15.0") { | |
}, | ||
|
||
quarter = function(x, with_year = FALSE, fiscal_start = 1) { | ||
check_bool(with_year) | ||
check_unsupported_arg(fiscal_start, 1, backend = "SQL Server") | ||
|
||
if (with_year) { | ||
|
@@ -361,6 +365,7 @@ simulate_mssql <- function(version = "15.0") { | |
sql_expr(DATEADD(YEAR, !!n, !!x)) | ||
}, | ||
date_build = function(year, month = 1L, day = 1L, ..., invalid = NULL) { | ||
check_unsupported_arg(invalid, allow_null = TRUE) | ||
sql_expr(DATEFROMPARTS(!!year, !!month, !!day)) | ||
}, | ||
get_year = function(x) { | ||
|
@@ -373,27 +378,16 @@ simulate_mssql <- function(version = "15.0") { | |
sql_expr(DATEPART(DAY, !!x)) | ||
}, | ||
date_count_between = function(start, end, precision, ..., n = 1L){ | ||
|
||
check_dots_empty() | ||
if (precision != "day") { | ||
cli_abort("{.arg precision} must be {.val day} on SQL backends.") | ||
} | ||
if (n != 1) { | ||
cli_abort("{.arg n} must be {.val 1} on SQL backends.") | ||
} | ||
check_unsupported_arg(precision, allowed = "day") | ||
simonpcouch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
check_unsupported_arg(n, allowed = 1L) | ||
|
||
sql_expr(DATEDIFF(DAY, !!start, !!end)) | ||
}, | ||
|
||
difftime = function(time1, time2, tz, units = "days") { | ||
|
||
if (!missing(tz)) { | ||
cli::cli_abort("The {.arg tz} argument is not supported for SQL backends.") | ||
} | ||
|
||
if (units[1] != "days") { | ||
cli::cli_abort('The only supported value for {.arg units} on SQL backends is "days"') | ||
} | ||
check_unsupported_arg(tz) | ||
check_unsupported_arg(units, allowed = "days") | ||
|
||
sql_expr(DATEDIFF(DAY, !!time2, !!time1)) | ||
} | ||
|
@@ -545,7 +539,7 @@ mssql_version <- function(con) { | |
|
||
#' @export | ||
`sql_returning_cols.Microsoft SQL Server` <- function(con, cols, table, ...) { | ||
stopifnot(table %in% c("DELETED", "INSERTED")) | ||
arg_match(table, values = c("DELETED", "INSERTED")) | ||
returning_cols <- sql_named_cols(con, cols, table = table) | ||
|
||
sql_clause("OUTPUT", returning_cols) | ||
|
@@ -637,6 +631,8 @@ mssql_bit_int_bit <- function(f) { | |
|
||
#' @export | ||
`db_sql_render.Microsoft SQL Server` <- function(con, sql, ..., cte = FALSE, use_star = TRUE) { | ||
check_unsupported_arg(cte, allowed = FALSE) | ||
simonpcouch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
check_unsupported_arg(use_star, allowed = TRUE) | ||
# Post-process WHERE to cast logicals from BIT to BOOLEAN | ||
sql$lazy_query <- purrr::modify_tree( | ||
sql$lazy_query, | ||
|
Uh oh!
There was an error while loading. Please reload this page.