Skip to content

Commit

Permalink
Create helper_file.R
Browse files Browse the repository at this point in the history
  • Loading branch information
vikram-rawat authored Sep 27, 2024
1 parent c527da1 commit dfa017e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions R/helper_file.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
generate_sql_statement <- function(sql_query, param_ls) {
sql_query <- sprintf(
fmt = "%s \n WHERE 1 = 1 \n", # Base query,
sql_query
)

lapply(
param_ls,
function(x) {
if (isTruthy(x$value)) {
if (x$wrap) {
in_values <- sprintf(
fmt = "('%s')",
paste(x$value, collapse = "','")
)
} else {
in_values <- x$value
}

sql_query <<- sprintf(
fmt = "%s AND \n %s %s %s \n",
sql_query,
x$col_name,
x$operator,
in_values
)
}
}
)

print("----------------")
cat(sql_query)
print("----------------")

return(sql_query)
}

0 comments on commit dfa017e

Please sign in to comment.