Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update howto-dm-db.Rmd #1211

Merged
merged 6 commits into from
Sep 20, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions vignettes/howto-dm-db.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ source("setup/setup.R")
To this end, a dm object can be created from any database that has a {[DBI](https://dbi.r-dbi.org/)} backend available ([see list](https://github.com/r-dbi/backends)).

When a dm object is created via a DBI connection to an RDBMS, it can import all the tables in the database, the active schema, or a limited set.
For some RDBMS, such as Postgres and SQL Server, primary and foreign keys are also imported and do not have to be manually added afterwards.
For some RDBMS, such as Postgres, SQL Server and MariaDB, primary and foreign keys are also imported and do not have to be manually added afterwards.

To demonstrate, we will connect to a `r href("relational dataset repository", "https://relational.fit.cvut.cz/")` with a database server that is publicly accessible without registration.
It hosts a `r href("financial dataset", "https://relational.fit.cvut.cz/dataset/Financial")` that contains loan data along with relevant account information and transactions.
We chose this dataset because the relationships between `loan`, `account`, and `transactions` tables are a good representation of databases that record real-world business transactions.
The repository uses a MariaDB server for which {dm} currently does not import primary or foreign keys, so we will need to add them.
Starting from version 0.3.0, {dm} does import primary and foreign keys also from MariaDB which this repository relies on. However, for demonstration purposes, we would act as if this would not be possible. So, we will add primary and foreign keys later on using the functions `dm_add_pk()` and `dm_add_fk()`.
krlmlr marked this conversation as resolved.
Show resolved Hide resolved

Below, we open a connection to the publicly accessible database server using their documented connection parameters.
Connection details vary from database to database. Before connecting to your own RDBMS, you may want to read `vignette("DBI", package = "DBI")` for further information.
Expand Down Expand Up @@ -55,7 +55,7 @@ Creating a dm object takes a single call to `dm_from_con()` with the DBI connect
``````{r}
library(dm)

my_dm <- dm_from_con(my_db)
my_dm <- dm_from_con(my_db, learn_keys = FALSE)
my_dm
``````

Expand Down