Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
daranzolin committed Jun 3, 2024
2 parents 3343f38 + cdc5199 commit 3a0faa0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Imports:
fs,
glue,
purrr,
readr,
rlang,
stringr,
tarchetypes,
Expand Down
7 changes: 2 additions & 5 deletions R/source_sql_to_dataframe.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
source_sql_to_dataframe <- function(path, query_params = NULL) {

lines <- readLines(path)
connection_string <- stringr::str_extract(lines[1], "(?<=\\=).*")
connection_string <- stringr::str_extract(readr::read_lines(path, n_max = 1), "(?<=\\=).*")
connection_call <- paste0("con <- ", connection_string)
eval(parse(text = connection_call))
on.exit(DBI::dbDisconnect(con))
delimiters <- strsplit(sqltargets_option_get("sqltargets.glue_sql_delimiters"), "")[[1]]
open <- delimiters[1]
close <- delimiters[2]
query <- lines[2:length(lines)]
query <- query[!grepl("tar_load", query)]
query <- paste(query, collapse = " ")
query <- readr::read_file(path)
query <- glue::glue_sql(query, .con = con, .open = open, .close = close, .envir = query_params)
out <- DBI::dbGetQuery(con, query)
msg <- glue::glue("{basename(path)} executed:\n Rows: {nrow(out)}\n Columns: {ncol(out)}")
Expand Down

0 comments on commit 3a0faa0

Please sign in to comment.