From 4a06d93e64f9c5130d35424ba12f9654f971500e Mon Sep 17 00:00:00 2001 From: drdolgovvv Date: Mon, 14 Sep 2026 13:40:02 +0300 Subject: [PATCH] devel: setup for sql-like data generation --- R/modules/db.R | 21 ++++++++++++++++++--- R/modules/utils.R | 10 ++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/R/modules/db.R b/R/modules/db.R index 8c17d90..0fda81c 100644 --- a/R/modules/db.R +++ b/R/modules/db.R @@ -1,3 +1,7 @@ +options(box.path = here::here()) +box::use( + R/modules/utils +) #' @export #' @description Function to open connection to db, disigned to easy dubugging. @@ -102,9 +106,6 @@ get_dummy_data = function(type) { #' типу данных get_dummy_df = function(forms_id_type_list) { - options(box.path = here::here()) - box::use(R/modules/utils) - purrr::map( .x = forms_id_type_list, .f = utils$get_empty_data @@ -113,6 +114,20 @@ get_dummy_df = function(forms_id_type_list) { } +#' @description +#' Генерация пустого датасета с пустыми значениями соответствующие +#' типу данных +get_query_df = function(forms_id_type_list) { + + names_and_types <- purrr::map( + .x = forms_id_type_list, + .f = utils$get_sql_format + ) + + paste(names(names_and_types), unname(names_and_types), collapse = ",\n") + +} + #' @description #' Сравнение полей в существующей в базе данных таблице и попытка #' коррекции таблицы diff --git a/R/modules/utils.R b/R/modules/utils.R index 1967036..3b71b8a 100644 --- a/R/modules/utils.R +++ b/R/modules/utils.R @@ -260,6 +260,16 @@ get_empty_data = function(type) { if (type %in% c("number")) as.character(NA) } +#' @export +#' @description +#' Функция возращает пустое значение для каждого типа формы +get_sql_format = function(type) { + if (type %in% c("text", "select_one", "select_multiple")) return("TEXT") + if (type %in% c("radio", "checkbox")) return("TEXT") + if (type %in% c("date")) return("REAL") + if (type %in% c("number")) return("TEXT") +} + #' @export #' @description Function to update input forms (default variants only) #' @param id - input form id;