refactor: some code tweaking

This commit is contained in:
2026-04-13 09:41:30 +03:00
parent f9d84bf245
commit 4225c4d382
5 changed files with 22 additions and 17 deletions

View File

@@ -4,7 +4,7 @@
#' not 'empty').
#'
#' Needed for proper data validation.
check_for_empty_data <- function(value_to_check) {
check_for_empty_data = function(value_to_check) {
# for any 0-length
if (length(value_to_check) == 0) return(TRUE)

View File

@@ -1,6 +1,6 @@
#' @export
init_val <- function(scheme, ns) {
init_val = function(scheme, ns) {
options(box.path = here::here())
box::use(modules/data_manipulations[check_for_empty_data])

View File

@@ -2,7 +2,7 @@
#' @export
#' @description Function to open connection to db, disigned to easy dubugging.
#' @param where text mark to distingiush calss
make_db_connection <- function(where = "") {
make_db_connection = function(where = "") {
if (getOption("APP.DEBUG", FALSE)) message("=== DB CONNECT ", where)
DBI::dbConnect(RSQLite::SQLite(), getOption("APP.FILE_DB", FALSE))
}
@@ -11,7 +11,7 @@ make_db_connection <- function(where = "") {
#' @description
#' Function to close connection to db, disigned to easy dubugging and
#' hide warnings.
close_db_connection <- function(con, where = "") {
close_db_connection = function(con, where = "") {
tryCatch(
expr = DBI::dbDisconnect(con),
error = function(e) print(e),
@@ -23,7 +23,7 @@ close_db_connection <- function(con, where = "") {
#' @export
#' @description
#' Проверить если таблица есть в базе данных и инициировать ее, если от
check_if_table_is_exist_and_init_if_not <- function(
check_if_table_is_exist_and_init_if_not = function(
schm,
con = rlang::env_get(rlang::caller_env(), nm = "con")
) {
@@ -79,7 +79,7 @@ check_if_table_is_exist_and_init_if_not <- function(
#' @description
#' Возращает пустое значение для каждого типа формы
get_dummy_data <- function(type) {
get_dummy_data = function(type) {
if (type %in% c("text", "select_one", "select_multiple")) return("dummy")
if (type %in% c("radio", "checkbox")) return("dummy")
@@ -92,7 +92,7 @@ get_dummy_data <- function(type) {
#' @description
#' Генерация пустого датасета с пустыми значениями соответствующие
#' типу данных
get_dummy_df <- function(forms_id_type_list) {
get_dummy_df = function(forms_id_type_list) {
options(box.path = here::here())
box::use(modules/utils)
@@ -108,7 +108,7 @@ get_dummy_df <- function(forms_id_type_list) {
#' @description
#' Сравнение полей в существующей в базе данных таблице и попытка
#' коррекции таблицы
compare_existing_table_with_schema <- function(
compare_existing_table_with_schema = function(
table_name,
schm,
con = rlang::env_get(rlang::caller_env(), nm = "con")
@@ -176,7 +176,7 @@ compare_existing_table_with_schema <- function(
}
#' @export
write_df_to_db <- function(
write_df_to_db = function(
df,
table_name,
schm,
@@ -225,7 +225,7 @@ write_df_to_db <- function(
#' @export
#' reading tables from db by name and id ========
read_df_from_db_by_id <- function(
read_df_from_db_by_id = function(
table_name,
schm,
main_key_value,
@@ -264,7 +264,7 @@ read_df_from_db_by_id <- function(
}
#' @export
get_keys_from_table <- function(table_name, schm, con) {
get_keys_from_table = function(table_name, schm, con) {
main_key_id <- schm$get_main_key_id
DBI::dbGetQuery(con, glue::glue("SELECT DISTINCT {main_key_id} FROM {table_name}")) |>
@@ -273,7 +273,7 @@ get_keys_from_table <- function(table_name, schm, con) {
}
#' @export
get_nested_keys_from_table <- function(table_name, schm, main_key_value, con) {
get_nested_keys_from_table = function(table_name, schm, main_key_value, con) {
main_key_id <- schm$get_main_key_id
key_id <- schm$get_key_id(table_name)
@@ -286,7 +286,7 @@ get_nested_keys_from_table <- function(table_name, schm, main_key_value, con) {
### HELPERS ---------
#' @export
excel_to_db_dates_converter <- function(date) {
excel_to_db_dates_converter = function(date) {
if (is.na(date)) return(NA)
# cli::cli_inform("date: {date} | nchar: {nchar(date)} | typeof: {typeof(date)}")

View File

@@ -1,6 +1,6 @@
#' @export
#' @description костыли для упрощения работы себе
set_global_options <- function(
set_global_options = function(
SYMBOL_DELIM = "; ",
APP.DEBUG = FALSE,
APP.FILE_DB = fs::path("data.sqlite"),
@@ -19,7 +19,7 @@ set_global_options <- function(
}
#' @export
check_and_init_scheme <- function() {
check_and_init_scheme = function() {
cli::cli_inform(c("*" = "проверка схемы..."))
@@ -54,7 +54,7 @@ check_and_init_scheme <- function() {
}
init_scheme <- function(scheme_file) {
init_scheme = function(scheme_file) {
options(box.path = here::here())
box::use(

View File

@@ -36,7 +36,12 @@ scheme_R6 <- R6::R6Class(
private$main_key_id <- self$get_key_id("main")
box::use(modules/utils)
private$testest <- utils$make_list_of_pages(private$schemes_list[["main"]], private$main_key_id)
private$testest <- bslib::navset_card_underline(
id = "main",
!!!utils$make_list_of_pages(private$schemes_list[["main"]], private$main_key_id),
header = NULL,
height = NULL
)
},
get_all_ids = function(table_name) {