Skip to content

Commit

Permalink
Update UPSERT documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jthompson-arcus committed Nov 7, 2024
1 parent 7b7114d commit 6e65f04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
16 changes: 11 additions & 5 deletions R/fct_SQLite.R
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,25 @@ db_update <- function(

#' UPSERT to all_review_data
#'
#' Performs an UPSERT on all_review_data. New records will be appended to the
#' table. Changed/updated records will be applied to the table based on the
#' index column constraint.
#'
#' @param con A DBI Connection to the SQLite DB
#' @param data A data frame containing the data to UPSERT into all_review_data
#' @param common_cols A character vector specifying which columns define a
#' unique row
#' @param idx_cols A character vector specifying which columns define a
#' unique index for a row
#'
#' @return invisibly returns TRUE. Is run for it's side effects on the DB.
#'
#' @keywords internal
db_upsert <- function(con, data, common_cols) {
db_upsert <- function(con, data, idx_cols) {
if ("id" %in% names(data))
data$id <- NULL
cols_to_update <- names(data)[!names(data) %in% common_cols]
cols_to_update <- names(data)[!names(data) %in% idx_cols]
cols_to_insert <- names(data) |>
paste(collapse = ", ")
constraint_cols <- paste(common_cols, collapse = ", ")
constraint_cols <- paste(idx_cols, collapse = ", ")
dplyr::copy_to(con, data, "row_updates")
rs <- DBI::dbSendStatement(con, paste(
"INSERT INTO",
Expand Down
13 changes: 9 additions & 4 deletions man/db_upsert.Rd

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

0 comments on commit 6e65f04

Please sign in to comment.