From dfa017e9e412f8db6a918361f09ceb3058566566 Mon Sep 17 00:00:00 2001 From: Anantadinath Date: Fri, 27 Sep 2024 17:15:38 +0530 Subject: [PATCH] Create helper_file.R --- R/helper_file.R | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 R/helper_file.R diff --git a/R/helper_file.R b/R/helper_file.R new file mode 100644 index 0000000..d2a4965 --- /dev/null +++ b/R/helper_file.R @@ -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) +}