dm_sql: Create _DDL_ and _DML_ scripts for a 'dm' a and database...

View source: R/dm_sql.R

dm_sqlR Documentation

Create DDL and DML scripts for a dm a and database connection

Description

[Experimental]

Generate SQL scripts to create tables, load data and set constraints, keys and indices. This function powers copy_dm_to() and is useful if you need more control over the process of copying a dm to a database.

Usage

dm_sql(dm, dest, table_names = NULL, temporary = TRUE)

dm_ddl_pre(dm, dest, table_names = NULL, temporary = TRUE)

dm_dml_load(dm, dest, table_names = NULL, temporary = TRUE)

dm_ddl_post(dm, dest, table_names = NULL, temporary = TRUE)

Arguments

dm

A dm object.

dest

Connection to database.

table_names

A named character vector or named vector of DBI::Id, DBI::SQL or dbplyr objects created with dbplyr::ident(), dbplyr::in_schema() or dbplyr::in_catalog(), with one unique element for each table in dm. The default, NULL, means to use the original table names.

temporary

Should the tables be marked as temporary? Defaults to TRUE.

Details

  • dm_ddl_pre() generates ⁠CREATE TABLE⁠ statements (including ⁠PRIMARY KEY⁠ definition).

  • dm_dml_load() generates ⁠INSERT INTO⁠ statements.

  • dm_ddl_post() generates scripts for ⁠FOREIGN KEY⁠, ⁠UNIQUE KEY⁠ and INDEX.

  • dm_sql() calls all three above and returns a complete set of scripts.

Value

Nested list of SQL statements.

Examples


con <- DBI::dbConnect(RSQLite::SQLite())
dm <- dm_nycflights13()
s <- dm_sql(dm, con)
s
DBI::dbDisconnect(con)


krlmlr/dm documentation built on April 19, 2024, 5:23 p.m.