Skip to contents

Join data from db_tbl and recent change values from chg_log tables. Attaches most recent 'WHO_EDITED' and 'WHEN_EDITED' form deltas table to primary table.

Usage

cdr_join_tbls(db_tbl, chg_log_tbl, key_col)

Arguments

db_tbl

primary table from DB

chg_log_tbl

deltas table from DB

key_col

the name of the unique ID column in the primary table

Value

tibble of the joined tables

Examples

chg_log_r_tbl <- structure(
list(
  OBS_ID = c( "ID-001", "ID-002"),
  FIELD = c("Species", "Sepal.Width"),
  CHG_FROM = c("setosa", "3.5"),
  CHG_TO = c("set", "5"),
  WHO_EDITED = c("joe", "fred"),
  WHEN_EDITED = c("11/29/2023, 1:36:46 AM", "11/28/2023, 5:39:21 PM")
),
class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -2L)
)
primary_r_tbl <- cdr_make_unique_ids(iris)
#> Auto generating Unique IDs for the table.
cdr_join_tbls(primary_r_tbl, chg_log_r_tbl, key_col = 'UID')
#> 
#>    --Running: cdr_join_tbls()
#> 	 Combine or Recombine primary and delta tables for UI.
#> # A tibble: 150 × 8
#>    UID    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>    <chr>         <dbl>       <dbl>        <dbl>       <dbl> <fct>  
#>  1 ID-001          5.1         3.5          1.4         0.2 setosa 
#>  2 ID-002          4.9         3            1.4         0.2 setosa 
#>  3 ID-003          4.7         3.2          1.3         0.2 setosa 
#>  4 ID-004          4.6         3.1          1.5         0.2 setosa 
#>  5 ID-005          5           3.6          1.4         0.2 setosa 
#>  6 ID-006          5.4         3.9          1.7         0.4 setosa 
#>  7 ID-007          4.6         3.4          1.4         0.3 setosa 
#>  8 ID-008          5           3.4          1.5         0.2 setosa 
#>  9 ID-009          4.4         2.9          1.4         0.2 setosa 
#> 10 ID-010          4.9         3.1          1.5         0.1 setosa 
#> # ℹ 140 more rows
#> # ℹ 2 more variables: WHO_EDITED_LAST <chr>, WHEN_EDITED_LAST <chr>