copy_dm_to() takes a dplyr::src_dbi object or a DBI::DBIConnection object as its first argument and a dm object as its second argument. The latter is copied to the former. By default, temporary tables will be created and the key constraints will be set (currently only on MSSQL and Postgres databases).

copy_dm_to(
dest,
dm,
...,
types = NULL,
overwrite = NULL,
indexes = NULL,
unique_indexes = NULL,
set_key_constraints = TRUE,
unique_table_names = NULL,
table_names = NULL,
temporary = TRUE
)

## Arguments

dest An object of class "src" or "DBIConnection". A dm object. Passed on to dplyr::copy_to(), which is used on each table. Must remain NULL. Boolean variable, if TRUE will mirror dm key constraints on a database. Deprecated. Desired names for the tables on dest; the names within the dm remain unchanged. Can be NULL, a named character vector, a function or a one-sided formula. If left NULL (default), the names will be determined automatically depending on the temporary argument: temporary = TRUE (default): unique table names based on the names of the tables in the dm are created. temporary = FALSE: the table names in the dm are used as names for the tables on dest. If a function or one-sided formula, table_names is converted to a function using rlang::as_function(). This function is called with the unquoted table names of the dm object as the only argument. The output of this function is processed by DBI::dbQuoteIdentifier(), that result should be a vector of identifiers of the same length as the original table names. Use a variant of table_names = ~ DBI::SQL(paste0("schema_name", ".", .x)) to specify the same schema for all tables. Use table_names = identity with temporary = TRUE to avoid giving temporary tables unique names. If a named character vector, the names of this vector need to correspond to the table names in the dm, and its values are the desired names on dest. The value is processed by DBI::dbQuoteIdentifier(), that result should be a vector of identifiers of the same length as the original table names. Use qualified names corresponding to your database's syntax to specify e.g. database and schema for your tables. Boolean variable, if TRUE, only temporary tables will be created. These tables will vanish when disconnecting from the database.

## Value

A dm object on the given src with the same table names as the input dm.

## Details

No tables will be overwritten; passing overwrite = TRUE to the function will give an error. Types are determined separately for each table, setting the types argument will also throw an error. The arguments are included in the signature to avoid passing them via the ... ellipsis.

## Examples

con <- DBI::dbConnect(RSQLite::SQLite())

# Copy to temporary tables, unique table names by default:
temp_dm <- copy_dm_to(
con,
dm_nycflights13(),
set_key_constraints = FALSE
)

# Persist, explicitly specify table names:
persistent_dm <- copy_dm_to(
con,
dm_nycflights13(),
temporary = FALSE,
table_names = ~ paste0("flights_", .x)
)
dbplyr::remote_name(persistent_dm\$planes)
#> <IDENT> flights_planes
DBI::dbDisconnect(con)