Skip to content

Commit

Permalink
Merge pull request #2552 from infotroph/dont-build-query
Browse files Browse the repository at this point in the history
remove build_insert_query, use dbAppendTable directly
  • Loading branch information
mdietze committed Mar 26, 2020
2 parents 4b11273 + b2725ba commit ffeff66
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ For more information about this file see also [Keep a Changelog](http://keepacha
- When building sipnet model would not set correct model version

### Changed
- `PEcAn.DB::insert_table` now uses `DBI::dbAppendTable` internally instead of manually constructed SQL (#2552).
- Rebuilt documentation using Roxygen 7. Readers get nicer formatting of usage sections, writers get more flexible behavior when inheriting parameters and less hassle when maintaining namespaces (#2524).
- Renamed functions that looked like S3 methods but were not:
* PEcAn.priors: `plot.posterior.density`->`plot_posterior.density`, `plot.prior.density`->`plot_prior.density`, `plot.trait`->`plot_trait` (#2439).
Expand Down
23 changes: 2 additions & 21 deletions base/db/R/insert_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#' dplyr::tbl(irisdb, "iris")
insert_table <- function(values, table, con, coerce_col_class = TRUE, drop = TRUE) {
values_fixed <- match_dbcols(values, table, con, coerce_col_class, drop = TRUE)
insert_query <- build_insert_query(values_fixed, table, .con = con)
db.query(insert_query, con)

DBI::dbAppendTable(con, table, values_fixed)
}

#' Match column names and classes between local and SQL table
Expand Down Expand Up @@ -91,22 +91,3 @@ match_colnames <- function(values, table, con) {
values_cols <- colnames(values)
intersect(values_cols, table_cols)
}

#' Build query to insert R data frame into SQL table
#'
#' @inheritParams insert_table
#' @inheritParams glue::glue_sql
build_insert_query <- function(values, table, .con) {
value_list <- purrr::map(seq_len(nrow(values)), ~as.list(values[.x, ]))

insert_list <- value_list %>%
purrr::map(unname) %>%
purrr::map(dbplyr::escape, con = .con) %>%
purrr::map(dbplyr::sql_vector, con = .con)

glue::glue_sql(
"INSERT INTO {`table`} ({`colnames(values)`*}) ",
"VALUES {insert_list*}",
.con = .con
)
}
18 changes: 0 additions & 18 deletions base/db/man/build_insert_query.Rd

This file was deleted.

0 comments on commit ffeff66

Please sign in to comment.