ctsit / redcapcustodian

Simplified, automated data management on REDCap systems
Other
13 stars 6 forks source link

Create `table_sync` to execute changes from `data_diff` #24

Closed pbchase closed 2 years ago

pbchase commented 2 years ago

Create table_sync, a function to update a DBI table accessible via a DBI connection with the output of the data_diff function (see issue #21 ) and options that indicate which of the CRUD operations should be executed.

sync_table <- function(
  conn,
  table,
  data_diff_output,
  insert = F,
  update = T,
  delete = F
) {
  # awesome stuff happens

  result <- list(
    inserts = insert_n,
    updates = update_n,
    deletes = deletes_n
  )
  return(result)
}

conn <- connect_to_redcap_db()

source <- read_csv("source_file.csv")
target <- tbl(conn, table) %>% collect()
differences <- data_diff(source, target)

sync_table(
  conn,
  table,
  differences,
  insert = F,
  update = T,
  delete = F
)
pbchase commented 2 years ago

Addressed by PR #47