Skip to content

separate in four steps how to read databases #77

Closed
@avallecam

Description

@avallecam

after some changes, I think we can separate the steps here into four subtitles. This will increase the possibility to show extra info within each step.

  1. connect with the database

show in a callout that this may look in real-life

# in real-life
db_con <- DBI::dbConnect(
  RSQLite::SQLite(), 
  host = "database.epiversetrace.com",
  user = "juanito",
  password = epiversetrace::askForPassword("Database password")
)
  1. write a local data frame as a table in the database

...

  1. read data from table
library(dbplyr)

# Take a reference of one table from the database
mydb <- tbl(src = db_con, "cases")

# Show the SQL queries translated
mydb %>% 
  dplyr::filter(confirm > 50) %>% 
  dplyr::arrange(desc(confirm)) %>% 
  dplyr::show_query()

# Pull all data down to a local tibble
mydb %>% 
  dplyr::filter(confirm > 50) %>% 
  dplyr::arrange(desc(confirm)) %>% 
  dplyr::collect()
  1. close database connection

...

Originally posted by @avallecam in #70 (comment)

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions