DRDataRaft/ docs
GitHub ↗

dr_target_database()

Writing and candidate validation require a DBI transaction. Before committing, the adapter reads the complete stored table and checks it against the contract. This catches constraint violations caused by driver casts as well as append conflicts with existing rows. It materializes the stored table in R. Append requires an explicit contract; direct replacement without one infers structure from the incoming table. dataraft.core::dr_run() always supplies its resolved contract.

Usage

dr_target_database(
  connection,
  table,
  mode = c("replace", "append"),
  transaction = TRUE,
  ...
)

Arguments

connection
DBI connection or zero-argument connection factory.


table
Table name or DBI::Id().


mode
Replace the table or append, with a gate before commit.


transaction
Must be TRUE. Nontransactional publication requires a custom dataraft.core::dr_write_target() adapter with an explicit consistency policy.


...
Named additional arguments to DBI::dbWriteTable().

Value

A target specification for dataraft.core::dr_set_target().

Details

The driver and table storage must support transactions, including rollback of replacement DDL. No silent fallback is provided. Coordinate concurrent writers externally; isolation and transactional DDL remain the driver's responsibility. Transactional SQLite and DuckDB are covered by the package tests. An arbitrary DBI driver or nontransactional table is not certified by a successful preflight. DuckDB connections reading or writing BIGINT/integer64 columns must use bigint = "integer64" to prevent lossy conversion. This is checked before appending to an existing BIGINT table and before validating a stored table. For append, dataraft.core::dr_collect(result) returns the transformed incoming batch; result$outputs$rows counts the complete destination and written_rows counts appended rows. Run quality evidence describes the complete candidate.

Caller connections stay open; factory connections close after success and failure. Extra arguments go to DBI::dbWriteTable(). Reserved arguments conn, name, value, append, and overwrite cannot be overridden.

Examples

\dontshow{if (requireNamespace("RSQLite", quietly = TRUE)) withAutoprint(\{ # examplesIf}
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
result <- dataraft.core::dr_product("orders") |>
  dataraft.core::dr_add_source(data.frame(id = 1:2)) |>
  dataraft.core::dr_set_target(dr_target_database(con, "orders")) |>
  dataraft.core::dr_run()
DBI::dbReadTable(con, "orders")
DBI::dbDisconnect(con)
\dontshow{\}) # examplesIf}
Documentation source snapshot · View source at 2f9432d ↗
Code examples are documented source examples; they are not executed in this website build.

Search documentation

Search functions, packages and guides.