
Last chance! 50% off unlimited learning
Sale ends in
Initialize a database using a defined schema
etl_init(
obj,
script = NULL,
schema_name = "init",
pkg = attr(obj, "pkg"),
ext = NULL,
...
)# S3 method for default
etl_init(
obj,
script = NULL,
schema_name = "init",
pkg = attr(obj, "pkg"),
ext = NULL,
...
)
find_schema(obj, schema_name = "init", pkg = attr(obj, "pkg"), ext = NULL, ...)
An etl
object
either a vector of SQL commands to be executed, or
a file path as a character vector containing an SQL initialization script.
If NULL
(the default), then the appropriate built-in
schema will be fetched by find_schema
, if it exists. Note
that the flavor of SQL in this file must match the type of the source. That is,
if your object is of type src_mysql
, then make sure that
the schema you specify here is written in MySQL (and not PostgreSQL). Please
note that SQL syntax is not, in general, completely portable. Use with caution, as this may
clobber any existing data you have in an existing database.
The name of the schema. Default is init
.
The package defining the schema. Should be set in etl
.
The file extension used for the SQL schema file. If NULL (the default) it
be inferred from the src_*
class of con
. For example, if con
has class SQLite
then ext
will be sqlite
.
Currently ignored
If the table definitions are at all non-trivial, you may wish to include a pre-defined table schema. This function will retrieve it.
cars <- etl("mtcars")
cars %>%
etl_init()
cars %>%
etl_init(script = sql("CREATE TABLE IF NOT EXISTS mtcars_alt (id INTEGER);"))
cars %>%
etl_init(schema_name = "init")
init_script <- find_schema(cars, schema_name = "init")
cars %>%
etl_init(script = init_script, echo = TRUE)
src_tbls(cars)
cars <- etl("mtcars")
find_schema(cars)
find_schema(cars, "init", "etl")
find_schema(cars, "my_crazy_schema", "etl")
Run the code above in your browser using DataLab