Skip to content

Commit

Permalink
Merge pull request #341 from r-dbi/b-339-list-objects
Browse files Browse the repository at this point in the history
feat: Relax `dbListObjects()` spec
  • Loading branch information
aviator-app[bot] authored Dec 24, 2023
2 parents 0965b0e + f6da034 commit 9c5c93e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
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.

0 comments on commit 9c5c93e

Please sign in to comment.