Skip to content

Commit

Permalink
add option to read query directly
Browse files Browse the repository at this point in the history
  • Loading branch information
vikram-rawat committed Mar 20, 2024
1 parent 97dc81d commit 0db0526
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: read.sql
Title: Reads .SQL Files And Execute Them
Version: 0.3.0
Version: 0.3.1
Authors@R:
person(
given = "Vikram",
Expand Down
18 changes: 11 additions & 7 deletions R/read_sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@
#' @description This function creates an object of type sql_query by reading the sql file.
#'
#' @param filepath path to an SQL file which has a query
#' @param sql_query_str a proper sql statement string if you don't want to read from a file
#' @param method Only 2 methods are allowed get and post short for getQuery and sendstatement
#'
#' @return character string
#'
#' @export

rs_read_query <- function(
filepath,
sql_query_str = "",
method = "get") {
method <- tolower(method)

if (!tolower(method) %in% c("get", "post")) {
stop("method can only be get or post")
}

sql_query <- readChar(
con = filepath,
nchars = file.info(filepath)$size,
useBytes = TRUE
)
if (nchar(sql_query_str) > 1) {
sql_query <- sql_query_str
} else {
sql_query <- readChar(
con = filepath,
nchars = file.info(filepath)$size,
useBytes = TRUE
)
}

sql_query <- structure(
.Data = list(
Expand Down

0 comments on commit 0db0526

Please sign in to comment.