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: Relax dbListObjects() spec #341

Merged
merged 2 commits into from
Dec 24, 2023
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 DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ VignetteBuilder:
Config/autostyle/scope: line_breaks
Config/autostyle/strict: false
Config/testthat/edition: 3
Config/Needs/check: decor
Encoding: UTF-8
KeepSource: true
Roxygen: list(markdown = TRUE)
Expand Down
16 changes: 4 additions & 12 deletions R/spec-sql-list-objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,19 @@ spec_sql_list_objects <- list(
#' For a call with the default `prefix = NULL`, the `table`
#' values that have `is_prefix == FALSE` correspond to the tables
#' returned from [dbListTables()],
non_prefix_objects <- vapply(
non_prefix_objects <- map_chr(
objects$table[!objects$is_prefix],
dbQuoteIdentifier,
conn = con,
character(1)
conn = con
)
all_tables <- dbQuoteIdentifier(con, dbListTables(con))
expect_equal(sort(non_prefix_objects), sort(as.character(all_tables)))

#'
#' The `table` object can be quoted with [dbQuoteIdentifier()].
sql <- lapply(objects$table[!objects$is_prefix], dbQuoteIdentifier, conn = con)
sql <- map(objects$table[!objects$is_prefix], dbQuoteIdentifier, conn = con)
#' The result of quoting can be passed to [dbUnquoteIdentifier()].
#' (We have to assume that the resulting identifier is a table, because one
#' cannot always tell from a quoted identifier alone whether it is a table
#' or a schema for example. As a consequence, the quote-unquote roundtrip
#' only works for tables (possibly schema-qualified), but not for other
#' database objects like schemata or columns.)
unquoted <- vapply(sql, dbUnquoteIdentifier, conn = con, list(1))
#' The unquoted results are equal to the original `table` object.
expect_equal(unquoted, unclass(objects$table[!objects$is_prefix]))
expect_error(walk(sql, dbUnquoteIdentifier, conn = con), NA)
#' (For backends it may be convenient to use the [Id] class, but this is
#' not required.)

Expand Down
6 changes: 0 additions & 6 deletions man/spec_sql_list_objects.Rd

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

Loading