Learn R Programming

dm (version 0.0.6.9000)

dm_learn_from_db: Learn a dm object from a database (DB)

Description

If there are any permament tables on a DB, a new dm object can be created that contains those tables, along with their primary and foreign key constraints.

Currently this only works with MSSQL and Postgres databases.

The default database schema will be used; it is currently not possible to parametrize the funcion with a specific database schema.

Usage

dm_learn_from_db(dest)

Arguments

dest

A src-object on a DB or a connection to a DB.

Value

A dm object with the tables from the DB and the respective key relations.

See Also

Other DB interaction functions: copy_dm_to()

Examples

Run this code
# NOT RUN {
if (FALSE) {
  library(dplyr)
  src_sqlite <- dplyr::src_sqlite(":memory:", create = TRUE)
  iris_key <- mutate(iris, key = row_number())

  # setting key constraints currently doesn't work on
  # SQLite but this would be the code to set the PK
  # constraint on the DB
  iris_dm <- copy_dm_to(
    src_sqlite,
    dm(iris = iris_key),
    set_key_constraints = TRUE
  )

  # and this would be the code to learn
  # the `dm` from the SQLite DB
  iris_dm_learned <- dm_learn_from_db(src_sqlite)
}
# }

Run the code above in your browser using DataLab