library(dplyr)
# Set up a test table
conn <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
artists_df <- data.frame(
ArtistId = c(1,2),
Name = c("AC/DC", "The Offspring")
)
DBI::dbWriteTable(conn, "Artist", artists_df)
# Update rows without changing the key.
artists <- tbl(conn, "Artist")
DBI::dbBegin(conn)
y <- data.frame(ArtistId = 1, Name = "DC/AC")
e_rows_update(
x = artists,
y = y,
by = "ArtistId",
in_place = TRUE)
DBI::dbRollback(conn)
# Update key values of rows.
DBI::dbBegin(conn)
y <- data.frame(ArtistId = 999, Name = "DC/AC")
match <- list(
x = data.frame("ArtistId" = 1),
y = data.frame("ArtistId" = 999)
)
e_rows_update(
x = artists,
y = y,
match = match,
by = "ArtistId",
in_place = TRUE)
DBI::dbRollback(conn)
DBI::dbDisconnect(conn)
Run the code above in your browser using DataLab