Learn R Programming

dcmodifydb (version 0.3.1)

dump_sql: Show generated sql

Description

Writes the generated sql to a file or command line. The script contains ALTER and UPDATE statements and can be used for documentation purposes.

Usage

dump_sql(x, table, con = NULL, file = stdout(), ...)

Arguments

x

dcmodify::modifier() object with rules to be written

table

either a dplyr::tbl() object or a character with table name

con

optional, when table is a character, a dbi connection.

file

to which the sql will be written.

...

not used

Value

character sql script with all statements.

Details

Note that when this script is run on the database it will change the original table. This differs from the default behavior of dcmodify which works on a (temporary) copy of the table.

Furthermore, it seems wise to wrap the generated SQL in a transaction when apply the SQL code on a database.

See Also

Other sql translation: modifier_to_sql()

Examples

Run this code
# NOT RUN {
# load modification rules and apply:
library(dcmodify)

con <- DBI::dbConnect(RSQLite::SQLite(), dbname=system.file("db/person.db", package="dcmodifydb"))
person <- dplyr::tbl(con, "person")

rules <- modifier(.file = system.file("db/corrections.yml", package="dcmodifydb"))
print(rules)

# show sql code generated from the rules.
dump_sql(rules, person)
# }

Run the code above in your browser using DataLab