Skip to content

Commit

Permalink
Merge pull request #462 from r-dbi/f-list-fields
Browse files Browse the repository at this point in the history
chore: Refactor `list_fields()`
  • Loading branch information
aviator-app[bot] authored Apr 1, 2024
2 parents e93306e + 1894174 commit 3957ee6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/dbListFields_PqConnection_Id.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @rdname postgres-tables
#' @usage NULL
dbListFields_PqConnection_Id <- function(conn, name, ...) {
list_fields(conn, name@name)
list_fields(conn, name)
}

#' @rdname postgres-tables
Expand Down
2 changes: 1 addition & 1 deletion R/dbListFields_PqConnection_character.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @usage NULL
dbListFields_PqConnection_character <- function(conn, name, ...) {
quoted <- dbQuoteIdentifier(conn, name)
id <- dbUnquoteIdentifier(conn, quoted)[[1]]@name
id <- dbUnquoteIdentifier(conn, quoted)[[1]]

list_fields(conn, id)
}
Expand Down
6 changes: 4 additions & 2 deletions R/tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,17 @@ find_temp_schema <- function(conn, fail_if_missing = TRUE) {
}

list_fields <- function(conn, id) {
query <- find_table(conn, id, "columns", only_first = TRUE)
name <- id@name

query <- find_table(conn, name, "columns", only_first = TRUE)
query <- paste0(
"SELECT column_name FROM ",
query, " ",
"ORDER BY ordinal_position"
)
fields <- dbGetQuery(conn, query)[[1]]
if (length(fields) == 0) {
stop("Table ", dbQuoteIdentifier(conn, id), " not found.", call. = FALSE)
stop("Table ", dbQuoteIdentifier(conn, name), " not found.", call. = FALSE)
}
fields
}

0 comments on commit 3957ee6

Please sign in to comment.