diff --git a/.Rbuildignore b/.Rbuildignore index 30c4dc6fdcb5afdd27e3438b2efc9ac636436e63..1ce1262ef563dc5d8819e8ad61e9c6f9b403eb63 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,4 @@ ^\.gitlab-ci\.yml$ ^ci/lib$ ^debug +^dev$ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 76a9299d2df1ca654371f54c06039478d8d610ad..557a70f6159df5ae2a8967bca75c24ab23786456 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,10 +41,23 @@ coverage: only: - master - production + - mise_en_place_test + before_script: + - echo "chargement paquets ubuntu" + - apt-get update + - apt-get install -y postgresql-16 postgresql-client-16 + - apt-get install -y postgis postgresql-16-postgis-3 + - apt-get install -y odbc-postgresql + - sudo service postgresql restart + - echo "preparation env postgres pour tests" + - ( echo CREATE USER runner WITH PASSWORD \'$BDD_RUNNER_PWD\' SUPERUSER; ) | sudo -u postgres psql -d template1 + - Rscript dev/0_prepa_env_test.R + script: - Rscript -e 'remotes::install_local(upgrade = "never")' - Rscript -e 'remotes::install_cran(c("covr", "DT"), upgrade = "never")' - Rscript -e 'covr::gitlab(quiet = FALSE)' + coverage: '/Coverage: \d+(?:\.\d+)?/' artifacts: paths: - public diff --git a/DESCRIPTION b/DESCRIPTION index f2c022763a3870868c8a6e4b1c2e2c3a93409791..663d46d7317f524e4091b22b203289cbc04a1080 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: datalibaba Title: Interface De Connexion a Une Base Posgres Postgis -Version: 0.0.0.9009 +Version: 0.0.0.9010 Authors@R: c(person(given = "Maël", family = "Theulière", @@ -9,7 +9,12 @@ Authors@R: person(given = "Juliette", family = "Engelaere Lefebvre", role = c("aut", "cre"), - email = "juliette.engelaere-lefebvre@developpement-durable.gouv.fr")) + email = "juliette.engelaere-lefebvre@developpement-durable.gouv.fr"), + person(given = "Edouard", + family = "Morin", + role = c("aut"), + email = "edouard.morin@developpement-durable.gouv.fr") + ) Description: Interface de connexion a une base Posgres : lecture, ecriture, consultation des schemas, gestion des types de donnees de R. License: GPL (>= 3) @@ -33,13 +38,18 @@ Imports: magrittr, tibble, units, - tidyr + tidyr, + lifecycle Suggests: knitr, - rmarkdown + rmarkdown, + testthat (>= 3.0.0), + backports, + lubridate Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) URL: https://dreal-pdl.gitlab-pages.din.developpement-durable.gouv.fr/csd/datalibaba/index.html, https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 VignetteBuilder: knitr +Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 525ea81d5b188469e0831f957d233e68a7957eb4..3eb7d46c5cb1eeff470d8a7c7c8e92bbdfb465f7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -25,6 +25,7 @@ export(poster_data) export(set_schema_rights) export(standard_var_pg) export(transferer_table_comments) +import(lifecycle) importFrom(DBI,Id) importFrom(DBI,dbConnect) importFrom(DBI,dbDisconnect) @@ -33,9 +34,9 @@ importFrom(DBI,dbExecute) importFrom(DBI,dbExistsTable) importFrom(DBI,dbGetQuery) importFrom(DBI,dbReadTable) -importFrom(DBI,dbSendQuery) importFrom(DBI,dbWriteTable) importFrom(RPostgreSQL,postgresqlpqExec) +importFrom(RPostgres,Postgres) importFrom(attempt,message_if) importFrom(attempt,message_if_none) importFrom(attempt,stop_if) @@ -65,6 +66,7 @@ importFrom(fs,path_home_r) importFrom(glue,glue) importFrom(magrittr,"%>%") importFrom(odbc,odbc) +importFrom(odbc,odbcListDrivers) importFrom(purrr,map) importFrom(purrr,map2_chr) importFrom(rlang,.data) diff --git a/NEWS.md b/NEWS.md index 6b7029f4c68be09f151bc4deabda22d9bb761b8e..b9da2ee1272565430f277dd4534e76acb9257803 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,10 @@ +# datalibaba 0.0.0.9010 +- Ajout de test unitaire +- bug fix post_dico_attr() plantait la session si le paramètre ecoSQL valait TRUE (#31) + # datalibaba 0.0.0.9009 - Gestion des tables non géo dans la fonction `importer_data` : Ajout d'une ligne pour définir explicitement `query_sql_limit` dans la fonction importer_data (cas d'une table non géo). - # datalibaba 0.0.0.9008 - Ajout d'un paramètre booleen `ecoSQL` à la fonction `connect_to_db` pour switcher de driver (passage du `DBI::dbDriver("PostgreSQL")` si `EcoSQL = FALSE`, à `RPostgres::Postgres()` si `ecoSQL = TRUE` adapté à l'usage de l'offre d'hébergement de base EcoSQL) diff --git a/R/commenter_champs.R b/R/commenter_champs.R index 86a076ecd17a7f1d107bb9d5aacb4aeeca9e4339..97bd5d56f56a8794b4f9848563266e582adf7394 100644 --- a/R/commenter_champs.R +++ b/R/commenter_champs.R @@ -11,7 +11,7 @@ #' @param ... eventuels autres arguments de la fonction d'ouverture de connexion `connect_to_db` #' #' @importFrom attempt stop_if stop_if_not -#' @importFrom DBI dbSendQuery dbDisconnect +#' @importFrom DBI dbExecute dbDisconnect #' @importFrom glue glue #' @importFrom rpostgis dbTableInfo #' @return NULL @@ -47,7 +47,7 @@ commenter_champs <- function(comment = NULL, var = NULL, table = NULL, schema = var2 <- paste0("\"", var, "\"") lib_var <- gsub("\'", "\'\'", comment) requete <- paste0("COMMENT ON COLUMN ", schema, ".", table, ".", var2, " IS \'", enc2utf8(lib_var), "\';") - DBI::dbSendQuery(conn = con, statement = requete) + DBI::dbExecute(conn = con, statement = requete) DBI::dbDisconnect(con) rm(con) @@ -65,7 +65,7 @@ commenter_champs <- function(comment = NULL, var = NULL, table = NULL, schema = #' @param ... eventuels autres arguments de la fonction d'ouverture de connexion `connect_to_db` #' #' @importFrom attempt stop_if_not stop_if -#' @importFrom DBI dbSendQuery dbDisconnect +#' @importFrom DBI dbExecute dbDisconnect #' @importFrom glue glue #' @importFrom purrr map #' @importFrom rpostgis dbTableInfo @@ -111,7 +111,7 @@ post_dico_attr <- function(dico = NULL, table = NULL, schema = NULL, db = "publi # ecriture de la requete de commentaire du champ commentaire <- paste0("COMMENT ON COLUMN ", schema, ".", table, ".", var, " IS \'", enc2utf8(lib_var), "\';") # execution de la requete - DBI::dbSendQuery(conn = con, statement = commentaire) + DBI::dbExecute(conn = con, statement = commentaire) } # Envoi des commentaires de champs en serie diff --git a/R/connect_to_db.R b/R/connect_to_db.R index bb4a30dbdb4ee6f57e56c42840510058f01b7165..55a9dc7d8a39cefbc4f53eddc489e8e3f16eb00c 100644 --- a/R/connect_to_db.R +++ b/R/connect_to_db.R @@ -1,16 +1,15 @@ -#' Connexion au serveur datamart +#' Connexion au serveur PostgreSQL #' #' @param db la database sur laquelle se connecter #' @param user le profil utilisateur avec lequel se connecter : does ou dreal, suffixe utilise pour les variable d'environnement #' @param user_id le nom utilisateur avec lequel se connecter tel que renseigné dans votre renviron #' @param user_pwd le mot de passe avec lequel se connecter tel que renseigné dans votre renviron -#' @param server l'adresse ip du serveur, laisser à NULL pour utiliser le variable d'environnement du .Renviron +#' @param server l'adresse ip du serveur PostgreSQL, laisser à NULL pour utiliser le variable d'environnement du .Renviron #' @param ecoSQL mettre à TRUE pour switcher vers un driver adapté à l'usage de l'offre d'hébergement de base EcoSQL (Experimental) #' @param ... eventuels autres arguments de la fonction d'ouverture de connexion `connect_to_db` #' @return La fonction cree un connecteur pour se connecter à la base posgresql du serveur via le driver DBI "PostgreSQL" ou `RPostgres::Postgres()` si `ecoSQL = TRUE`. #' @importFrom DBI dbDriver dbConnect -#' @importFrom odbc odbc -#' @importFrom glue glue +#' @importFrom RPostgres Postgres #' @export #' #' @examples @@ -45,17 +44,18 @@ connect_to_db <- function(db = "datamart", } -#' Connexion au serveur via ODBC connection string +#' Connexion au serveur PostgreSQL via ODBC connection string #' #' @param db la database sur laquelle se connecter #' @param user le profil utilisateur avec lequel se connecter : does ou dreal #' @param user_id le nom utilisateur avec lequel se connecter tel que renseigné dans votre renviron #' @param user_pwd le mot de passe avec lequel se connecter tel que renseigné dans votre renviron #' @param server l'adresse ip du serveur, laisser à NULL pour utiliser le variable d'environnement du .Renviron +#' @param driver choix du driver (actuellement seul PostgreSQL est accepté) #' @return La fonction créé un connecteur pour se connecter à la base posgresql du serveur via le driver "PostgreSQL". #' @return Un connecteur con #' @importFrom DBI dbDriver dbConnect -#' @importFrom odbc odbc +#' @importFrom odbc odbc odbcListDrivers #' @importFrom glue glue #' @export #' @@ -67,20 +67,38 @@ connect_to_dbi <- function(db="datamart", user="does", user_id=paste0("user_",user), user_pwd = paste0("pwd_",user), - server = NULL){ + server = NULL, + driver = "PostgreSQL"){ + + required_driver <- all( + driver %in% c(NULL,"PostgreSQL") #liste a enrichir si on souhaite permettre d autre SGBD comme mariaDB... + ) + if (isFALSE(required_driver)) { + stop("The driver must be NULL or 'PostgreSQL'") + } + if(!is.null(driver) && driver == "PostgreSQL"){patterndriver <-"^Postgre.*UNICODE|Unicode.*"} + else{patterndriver <- "^_"}#si driver NULL fail if(is.null(server)) {server <- Sys.getenv("server")} + dbi_user <- Sys.getenv(user_id) + dbi_pwd <- Sys.getenv(user_pwd) - con_chaine <- glue::glue("Driver={PostgreSQL Unicode(x64)};Server=$server$;\nDatabase=$db$;\nUID=$user_id$;\nPWD=$user_pwd$;\nPort=$Sys.getenv('port')$;", + listdriver<-odbc::odbcListDrivers() + drv_unicode_postgres <- listdriver$name[grepl(patterndriver, listdriver$name)][1] + if(!is.na(drv_unicode_postgres)){ + #voir https://www.connectionstrings.com/ + con_chaine <- glue::glue("Driver={",drv_unicode_postgres,"};Server=$server$;Database=$db$;Uid=$dbi_user$;Pwd=$dbi_pwd$;Port=$Sys.getenv('port')$;", .open = "$", .close= "$") - con <- DBI::dbConnect(odbc::odbc(), - .connection_string = , + .connection_string = con_chaine, timeout = 10, encoding = "UTF-8") + }else{ + stop("alert: Pas de driver Postgresql pour ODBC") + } # if(.Platform$OS.type == "windows") { - # DBI::dbSendQuery(con,"SET client_encoding TO \'windows-1252\'") + # DBI::dbExecute(con,"SET client_encoding TO \'windows-1252\'") # } return(con) diff --git a/R/get_data.R b/R/get_data.R index cda29320b6a2587faa3989e3189595942e39d570..b51d56f0047b11d5eb3f1fe1ee97393be4840076 100644 --- a/R/get_data.R +++ b/R/get_data.R @@ -23,7 +23,7 @@ #' \dontrun{ #' importer_data(table = "test_iris", schema = "public", db = "public", user = "does") #' } -#' @source {rpostgis} http://mablab.org/rpostgis/ +#' @source \\{rpostgis}\\ http://mablab.org/rpostgis/ importer_data <- function(table = NULL, schema = NULL, db = "public", server = NULL, user = "does", limit = 0, ...) { @@ -31,20 +31,20 @@ importer_data <- function(table = NULL, schema = NULL, db = "public", server = attempt::stop_if(schema, is.null, msg = "l'argument schema n'est pas renseign\u00e9") attempt::stop_if(db, is.null, msg = "l'argument db n'est pas renseign\u00e9") attempt::stop_if(user, is.null, msg = "l'argument user n'est pas renseign\u00e9") - attempt::stop_if_not(limit, is.numeric, msg = "l'argument user n'est pas num\u00e9rique") + attempt::stop_if_not(limit, is.numeric, msg = "l'argument limit n'est pas num\u00e9rique") con <- connect_to_db(db = db, user = user, server = server, ...) ecoSQL <- grepl("RPostgres", attributes(class(con))) if(ecoSQL) name = DBI::Id(schema = schema, table = table) else name = c(schema, table) attempt::stop_if_not(DBI::dbExistsTable(conn = con, name = name), - msg = paste0("La table '", paste(name, collapse = "'.'"), "' est introuvable.")) + msg = paste0("La table '", paste(c(schema, table), collapse = "'.'"), "' est introuvable.")) # on recupere la liste des noms de champs de la table et leurs caracteristiques champs <- rpostgis::dbTableInfo(conn = con, name = c(schema, table), allinfo = FALSE) # recupere-t-on des proprietes de dataframe R dans zz_r_df_def ? - if(ecoSQL) name_r_def = DBI::Id(schema = schema, table = "zz_r_df_def") else name_r_def = c(schema, "zz_r_df_def") + if(ecoSQL) name_r_def = DBI::Id(schema = schema, table = "zz_r_df_def") else name_r_def = c(schema, "zz_r_df_def") if(DBI::dbExistsTable(conn = con, name = name_r_def)) { def_table <- DBI::dbReadTable(con, name_r_def) %>% dplyr::filter(.data$table_nm == table) @@ -91,8 +91,8 @@ importer_data <- function(table = NULL, schema = NULL, db = "public", server = if ("id_row__" %in% champs$column_name) { - data <- dplyr::arrange(.data = data, .data$id_row__) %>% - dplyr::select(-.data$id_row__) + data <- data %>% dplyr::arrange(.data$id_row__) %>% + dplyr::select(-"id_row__") } } @@ -199,6 +199,7 @@ get_data <- function(con = NULL, schema = NULL, table = NULL) { attempt::stop_if(con, is.null, msg = "con n'est pas renseign\u00e9") + attempt::stop_if_not(class(con) == "PostgreSQLConnection", msg = "veuillez utiliser une connexion avec ecoSQL=FALSE") attempt::stop_if(schema, is.null, msg = "schema n'est pas renseign\u00e9") attempt::stop_if(table, is.null, msg = "table n'est pas renseign\u00e9") @@ -215,7 +216,7 @@ get_data <- function(con = NULL, #' @param schema Le nom du schema sur le serveur de données. #' @param table Le nom de la table sur le serveur de données. #' @importFrom attempt stop_if -#' @importFrom DBI dbSendQuery dbReadTable Id +#' @importFrom DBI dbReadTable Id #' #' @return un dataframe #' @export @@ -224,6 +225,7 @@ get_data_dbi <- function(con = NULL, schema = NULL, table = NULL) { attempt::stop_if(con, is.null, msg = "con n'est pas renseign\u00e9") + attempt::stop_if_not(class(con) == "PqConnection", msg = "veuillez utiliser une connexion avec ecoSQL=TRUE") attempt::stop_if(schema, is.null, msg = "schema n'est pas renseign\u00e9") attempt::stop_if(table, is.null, msg = "table n'est pas renseign\u00e9") tbl <- DBI::Id(schema = schema, table = table) diff --git a/R/list_tables.R b/R/list_tables.R index 854a2eeda4343a78b82978e9930bb5fb7aad51a0..738149f6b8a4a25af16f2db23523778b11182c4d 100644 --- a/R/list_tables.R +++ b/R/list_tables.R @@ -7,6 +7,7 @@ #' @param ... eventuels autres arguments de la fonction d'ouverture de connexion `connect_to_db` #' @return Un vecteur de caractères avec les tables présentes sur le schéma schema du connecteur con. #' @importFrom attempt stop_if_all message_if_none stop_if stop_if_not +#' @importFrom dplyr arrange select #' @importFrom DBI dbGetQuery dbDisconnect #' @importFrom glue glue #' @export @@ -39,8 +40,9 @@ list_tables <- function(con = NULL, schema = NULL, db = NULL, user = NULL, ...) if(con_a_creer_fermer) { DBI::dbDisconnect(connexion) } - - return(all_tables$table_name) + res <- all_tables %>% arrange(.data$table_name) + res <- res$table_name + return(res) } diff --git a/R/post_data.R b/R/post_data.R index 80efc24b89323b380235c726f5ed02ae37a63454..896f775451026418e04459039642c1aad763b8f1 100644 --- a/R/post_data.R +++ b/R/post_data.R @@ -29,7 +29,7 @@ #' poster_data(data = iris, table = "test_iris", schema = "public", db = "public", #' pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "does") #' } -#' @source {rpostgis} http://mablab.org/rpostgis/ +#' @source \\{rpostgis}\\ http://mablab.org/rpostgis/ poster_data <- function(data = NULL, table = NULL, @@ -71,7 +71,6 @@ poster_data <- function(data = NULL, ## découverte du type de connexion ecoSQL <- grepl("RPostgres", attributes(class(con))) - ## Creation de la table des definitions utiles pour le reimport dans R du jeu de donnee------------ if(ecoSQL) nom_table = DBI::Id(schema = schema, table = "zz_r_df_def") else nom_table = c(schema, "zz_r_df_def") @@ -84,7 +83,7 @@ poster_data <- function(data = NULL, rpostgis::dbAddKey(conn = con, c(schema, "zz_r_df_def"), colname = "table_nm", type = "primary") rpostgis::dbComment(conn = con, c(schema, "zz_r_df_def"), - comment = "Table holding R dataframes columns definitions (for import/export using rpostgis :: db(Read/Write)DataFrame) or {datalibaba}.") + comment = "Table holding R dataframes columns definitions (for import/export using rpostgis :: db(Read/Write)DataFrame) or datalibaba.") }) message("Nouvelle table de d\u00e9finition des R dataframes R cr\u00e9\u00e9e : ", schema, ".\"zz_r_df_def\".") @@ -260,7 +259,8 @@ post_data <- function(con, overwrite = FALSE ) { attempt::stop_if(con, is.null, msg = "con n\'est pas renseign\u00e9") - attempt::stop_if_not(deparse(substitute(con)), exists, msg = glue::glue("le connecteur {con} n\'existe pas")) + attempt::stop_if_not(deparse(substitute(con)), exists, msg = "le connecteur con n\'existe pas dans l\'environnement") + attempt::stop_if_not(class(con) == "PostgreSQLConnection", msg = "veuillez utiliser une connexion avec ecoSQL=FALSE") attempt::stop_if(data, is.null, msg = "data n\'est pas renseign\u00e9") attempt::stop_if_not(data, is.data.frame, msg = glue::glue("le dataframe {data} n\'exsiste pas")) attempt::stop_if(schema, is.null, msg = "schema n\'est pas renseign\u00e9") @@ -274,18 +274,26 @@ post_data <- function(con, #' Chargement d'un dataset sur le serveur en dbi +#' @description +#' `r lifecycle::badge("deprecated")` +#' +#' Cette fonction a été dépréciée car non fonctionnelle en l'état +#' Elle désormais équivalente à post_data et il est conseillé d'utiliser +#' poster_data #' #' @param con Le connecteur de classe PosgreSQLConnection. #' @param data Un dataframe a importer. #' @param schema Le nom du schema sur le serveur de donnees. #' @param table Le nom de la table sur le serveur de donnees. #' @param overwrite TRUE si on veut ecraser le fichier deja present. +#' @import lifecycle #' @importFrom attempt stop_if stop_if_not -#' @importFrom DBI dbWriteTable Id dbSendQuery +#' @importFrom DBI dbWriteTable Id #' @importFrom glue glue #' #' @return NULL, la fonction lance le chargement du dataset present dans l'environnement R et son ecriture sur le serveur #' @export +#' @keywords internal #' post_data_dbi <- function(con = NULL, @@ -293,16 +301,7 @@ post_data_dbi <- function(con = NULL, schema = NULL, table = NULL, overwrite = FALSE) { - attempt::stop_if(con, is.null, msg = "con n\'est pas renseign\u00e9") - attempt::stop_if_not(deparse(substitute(con)), exists, msg = glue::glue("le connecteur {con} n\'existe pas")) - attempt::stop_if(data, is.null, msg = "data n\'est pas renseign\u00e9") - attempt::stop_if_not(data, is.data.frame, msg = glue::glue("le dataframe {data} n\'exsiste pas")) - attempt::stop_if(schema, is.null, msg = "schema n\'est pas renseign\u00e9") - attempt::stop_if(table, is.null, msg = "table n\'est pas renseign\u00e9") - attempt::stop_if_not(schema, ~ .x %in% list_schemas(con), msg = glue::glue("le schema {schema} n\'existe pas")) - attempt::stop_if(table %in% list_tables(con,schema) & !overwrite, msg = glue::glue("La table {table} existe d\u00e9j\u00e0 sur le schema {schema} et le param\u00e8 tre overwrite est \u00e0 FALSE")) - tbl <- DBI::Id(schema = schema, table = table) - DBI::dbWriteTable(con, tbl, data, overwrite = overwrite ) - return(invisible(NULL)) + lifecycle::deprecate_warn("0.0.0.9010", "post_data_dbi()", "poster_data()") + post_data(con=con, data = data, schema = schema, table = table, overwrite = overwrite) } diff --git a/R/set_shema_rights.R b/R/set_shema_rights.R index fbb6abf2c1834b3f85c1f56dfc45829881edef6d..69148235dc76d8460cf32935c401c7579ec1ba2b 100644 --- a/R/set_shema_rights.R +++ b/R/set_shema_rights.R @@ -51,22 +51,24 @@ set_schema_rights <- function(schema = "public", table = NULL, con = NULL, db = tables_concernees <- ifelse(is.null(table), "ALL TABLES", table) - droit2 <- dplyr::transmute(droits, liste_priv = gsub("\\{|\\}", "", .data$liste_priv) %>% strsplit(split = ",") %>% list) %>% - dplyr::summarise(liste_priv = list(unlist(.data$liste_priv)) ) %>% - dplyr::pull(.data$liste_priv) %>% unlist() %>% tibble::enframe(name = NULL) %>% - tidyr::separate(col = .data$value, sep = "([=/])", into = c("role", "droits", "granter"), remove = TRUE) %>% - dplyr::select(-.data$granter) %>% - dplyr::distinct() %>% - mutate(privilege = dplyr::case_when( - .data$droits == "arwdDxt" ~ "ALL", - .data$droits == "r" ~ "SELECT", - TRUE ~ purrr::map2_chr(.x = ref_privilege$abrv, .y = ref_privilege$verbe, .f = ~ ifelse(grepl(pattern = .x, .data$droits), .y, NA_character_)) %>% - setdiff(., NA_character_) %>% - paste(collapse = ", ") - ), - sql = paste0("GRANT ", .data$privilege," ON ", tables_concernees ," IN SCHEMA ", schema ," TO ", .data$role, ";") - ) + ## non fonctionnel pour le moment + # droit2 <- dplyr::transmute(droits, liste_priv = gsub("\\{|\\}", "", .data$liste_priv) %>% strsplit(split = ",") %>% list) %>% + # dplyr::summarise(liste_priv = list(unlist(.data$liste_priv)) ) %>% + # dplyr::pull(.data$liste_priv) %>% unlist() %>% tibble::enframe(name = NULL) %>% + # tidyr::separate(col = .data$value, sep = "([=/])", into = c("role", "droits", "granter"), remove = TRUE) %>% + # dplyr::select(-.data$granter) %>% + # dplyr::distinct() %>% + # mutate(privilege = dplyr::case_when( + # .data$droits == "arwdDxt" ~ "ALL", + # .data$droits == "r" ~ "SELECT", + # TRUE ~ purrr::map2_chr(.x = ref_privilege$abrv, .y = ref_privilege$verbe, .f = ~ ifelse(grepl(pattern = .x, .data$droits), .y, NA_character_)) %>% + # setdiff(., NA_character_) %>% + # paste(collapse = ", ") + # ), + # sql = paste0("GRANT ", .data$privilege," ON ", tables_concernees ," IN SCHEMA ", schema ," TO ", .data$role, ";") + # ) + return(invisible(NULL)) } diff --git a/README.Rmd b/README.Rmd index d8cba4f5160994ebe642ebb18c61cdb0296d39b9..f768b77d59e1904e06186571ed715587afcd2bde 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,6 +17,7 @@ knitr::opts_chunk$set( <!-- badges: start --> +[](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/master)[](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/master) <!-- badges: end --> {datalibaba} est un ensemble de fonctions visant à faciliter l'alimentation du serveur de données du DREAL <datalab/> Pays de la Loire. diff --git a/README.md b/README.md index ddf690f352181cfa28749b9f0ad55b93474020cb..e30c7abe68724a76e6cd6a741aab3bca574dddd8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ # datalibaba <img src='man/figures/logo.png' align="right" height="139" /> <!-- badges: start --> + +[](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/master)[](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/master) <!-- badges: end --> {datalibaba} est un ensemble de fonctions visant à faciliter diff --git a/datalibaba.Rproj b/datalibaba.Rproj index 69fafd4b6dddad27500cfc67efb9fb16e86a96bd..8a479e3496adb9fa29aa0caef612b9ffd5acadca 100644 --- a/datalibaba.Rproj +++ b/datalibaba.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 643276e3-9018-4b1c-85b4-c14054b6bc51 RestoreWorkspace: No SaveWorkspace: No diff --git a/dev/0_prepa_env_test.R b/dev/0_prepa_env_test.R new file mode 100644 index 0000000000000000000000000000000000000000..dae161003ab45f49ff3a45e8c36e2e9084f17d86 --- /dev/null +++ b/dev/0_prepa_env_test.R @@ -0,0 +1,22 @@ +install.packages("DBI") +install.packages("odbc") + +if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + con <- DBI::dbConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres") + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="test_datalibaba") == TRUE){ + DBI::dbExecute(con, "DROP DATABASE IF EXISTS test_datalibaba;") + } + DBI::dbExecute(con, "CREATE DATABASE test_datalibaba WITH OWNER = runner ENCODING = 'UTF8' CONNECTION LIMIT = -1;") + DBI::dbDisconnect(con) + con <- DBI::dbConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="test_datalibaba") + DBI::dbExecute(con, "CREATE EXTENSION postgis;") + DBI::dbExecute(con, "CREATE EXTENSION postgis_topology;") + + #autre dbExecute si besoin de plus + #si on veut lire un script sql mesreq.sql, le mettre dans /dev et executer + # system(paste0("( echo dev/mesreq.sql ) | psql \"postgresql://runner:",Sys.getenv("BDD_RUNNER_PWD"),"@127.0.0.1:5432/test_datalibaba\"")) + print('local database postgresql works !') +}else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('alert: local database postgresql doesnt work !') +} diff --git a/dev/config_attachment.yaml b/dev/config_attachment.yaml new file mode 100644 index 0000000000000000000000000000000000000000..46e24ecc2173ddbd6d930225a01bb92e508508d5 --- /dev/null +++ b/dev/config_attachment.yaml @@ -0,0 +1,12 @@ +path.n: NAMESPACE +path.d: DESCRIPTION +dir.r: R +dir.v: vignettes +dir.t: tests +extra.suggests: ~ +pkg_ignore: ~ +document: yes +normalize: yes +inside_rmd: no +must.exist: yes +check_if_suggests_is_installed: yes diff --git a/man/connect_to_db.Rd b/man/connect_to_db.Rd index 0d781123910aee8b47d9e409215134fe5619e995..080a84245f4e6b08030e36cb65133dc5083e0c95 100644 --- a/man/connect_to_db.Rd +++ b/man/connect_to_db.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/connect_to_db.R \name{connect_to_db} \alias{connect_to_db} -\title{Connexion au serveur datamart} +\title{Connexion au serveur PostgreSQL} \usage{ connect_to_db( db = "datamart", @@ -23,7 +23,7 @@ connect_to_db( \item{user_pwd}{le mot de passe avec lequel se connecter tel que renseigné dans votre renviron} -\item{server}{l'adresse ip du serveur, laisser à NULL pour utiliser le variable d'environnement du .Renviron} +\item{server}{l'adresse ip du serveur PostgreSQL, laisser à NULL pour utiliser le variable d'environnement du .Renviron} \item{ecoSQL}{mettre à TRUE pour switcher vers un driver adapté à l'usage de l'offre d'hébergement de base EcoSQL (Experimental)} @@ -33,7 +33,7 @@ connect_to_db( La fonction cree un connecteur pour se connecter à la base posgresql du serveur via le driver DBI "PostgreSQL" ou \code{RPostgres::Postgres()} si \code{ecoSQL = TRUE}. } \description{ -Connexion au serveur datamart +Connexion au serveur PostgreSQL } \examples{ \dontrun{ diff --git a/man/connect_to_dbi.Rd b/man/connect_to_dbi.Rd index 52aa1c31c2f5633c76926d50663fa2f02af31be9..a22c51ef8466011bb862fcd7f188349fa412b528 100644 --- a/man/connect_to_dbi.Rd +++ b/man/connect_to_dbi.Rd @@ -2,14 +2,15 @@ % Please edit documentation in R/connect_to_db.R \name{connect_to_dbi} \alias{connect_to_dbi} -\title{Connexion au serveur via ODBC connection string} +\title{Connexion au serveur PostgreSQL via ODBC connection string} \usage{ connect_to_dbi( db = "datamart", user = "does", user_id = paste0("user_", user), user_pwd = paste0("pwd_", user), - server = NULL + server = NULL, + driver = "PostgreSQL" ) } \arguments{ @@ -22,6 +23,8 @@ connect_to_dbi( \item{user_pwd}{le mot de passe avec lequel se connecter tel que renseigné dans votre renviron} \item{server}{l'adresse ip du serveur, laisser à NULL pour utiliser le variable d'environnement du .Renviron} + +\item{driver}{choix du driver (actuellement seul PostgreSQL est accepté)} } \value{ La fonction créé un connecteur pour se connecter à la base posgresql du serveur via le driver "PostgreSQL". @@ -29,7 +32,7 @@ La fonction créé un connecteur pour se connecter à la base posgresql du serve Un connecteur con } \description{ -Connexion au serveur via ODBC connection string +Connexion au serveur PostgreSQL via ODBC connection string } \examples{ \dontrun{ diff --git a/man/importer_data.Rd b/man/importer_data.Rd index 323a650d40e84953ebbbb60dce94d8240b9f9705..78132ab9f3f0fda4a9bd6ca230e001bf655a75a5 100644 --- a/man/importer_data.Rd +++ b/man/importer_data.Rd @@ -4,7 +4,7 @@ \alias{importer_data} \title{Import d'une table a partir du serveur de donnees, fonction qui s'adapte aux types de table a charger : recuperation des modalites des facteurs si chargee avec {rpostgis}, sf dataframe si table geographique.} \source{ -{rpostgis} http://mablab.org/rpostgis/ +\\{rpostgis}\\ http://mablab.org/rpostgis/ } \usage{ importer_data( diff --git a/man/post_data_dbi.Rd b/man/post_data_dbi.Rd index 41cdd26a1adf6cac7769d707764518cfc0ba9674..b703afe7f24b8eeeed5d6910b488e0377b6b11c3 100644 --- a/man/post_data_dbi.Rd +++ b/man/post_data_dbi.Rd @@ -27,5 +27,10 @@ post_data_dbi( NULL, la fonction lance le chargement du dataset present dans l'environnement R et son ecriture sur le serveur } \description{ -Chargement d'un dataset sur le serveur en dbi +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} + +Cette fonction a été dépréciée car non fonctionnelle en l'état +Elle désormais équivalente à post_data et il est conseillé d'utiliser +poster_data } +\keyword{internal} diff --git a/man/poster_data.Rd b/man/poster_data.Rd index e2aa254398c80b0d16fc77ad5225500121387305..d0071ff5675f260c2df0258ad6a420b1d3a03536 100644 --- a/man/poster_data.Rd +++ b/man/poster_data.Rd @@ -4,7 +4,7 @@ \alias{poster_data} \title{Chargement d'un dataset sur le serveur avec rpostgis. Par rapport aux autres fonctions \code{post_data()}, \code{post_data_pg()} ouvre et ferme la connexion au SGBD, gere les dataframes spatiaux et les facteurs, et poste quelques metadonnees en commentaire de la table.} \source{ -{rpostgis} http://mablab.org/rpostgis/ +\\{rpostgis}\\ http://mablab.org/rpostgis/ } \usage{ poster_data( diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000000000000000000000000000000000000..c6bae3043b1e14fd2dd543ee498108a3f8455bc4 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(datalibaba) + +test_check("datalibaba") diff --git a/tests/testthat/_snaps/4-post_data.md b/tests/testthat/_snaps/4-post_data.md new file mode 100644 index 0000000000000000000000000000000000000000..c1cd496cdde44c051d2ea836cb08913142ae62c9 --- /dev/null +++ b/tests/testthat/_snaps/4-post_data.md @@ -0,0 +1,14 @@ +# poster_data works + + Code + list_tables(schema = schem, db = "test_datalibaba", user = "test") + Output + character(0) + +--- + + Code + list_tables(schema = schem, con = con) + Output + character(0) + diff --git a/tests/testthat/_snaps/5-get_data.md b/tests/testthat/_snaps/5-get_data.md new file mode 100644 index 0000000000000000000000000000000000000000..329e3d10098ce6c978ba5e82b903c10e8b8aec32 --- /dev/null +++ b/tests/testthat/_snaps/5-get_data.md @@ -0,0 +1,711 @@ +# importer_data no geo works + + Code + importer_data(table = "test_iris", schema = "public", db = "test_datalibaba", + user = "test", limit = 4, ecoSQL = FALSE) + Output + id Sepal.Length Sepal.Width Petal.Length Petal.Width Species + 1 1 5.1 3.5 1.4 0.2 setosa + 2 2 4.9 3.0 1.4 0.2 setosa + 3 3 4.7 3.2 1.3 0.2 setosa + 4 4 4.6 3.1 1.5 0.2 setosa + todate + 1 2025-02-27 14:29:32 + 2 2025-02-27 14:29:32 + 3 2025-02-27 14:29:32 + 4 2025-02-27 14:29:32 + +# importer_data geo works + + Code + importer_data(table = "nc", schema = "public", db = "test_datalibaba", user = "test") + Output + Simple feature collection with 100 features and 14 fields + Geometry type: MULTIPOLYGON + Dimension: XY + Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 + Geodetic CRS: NAD27 + First 10 features: + AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 + 1 0.114 1.442 1825 1825 Ashe 37009 37009 5 1091 1 + 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 + 3 0.143 1.630 1828 1828 Surry 37171 37171 86 3188 5 + 4 0.070 2.968 1831 1831 Currituck 37053 37053 27 508 1 + 5 0.153 2.206 1832 1832 Northampton 37131 37131 66 1421 9 + 6 0.097 1.670 1833 1833 Hertford 37091 37091 46 1452 7 + 7 0.062 1.547 1834 1834 Camden 37029 37029 15 286 0 + 8 0.091 1.284 1835 1835 Gates 37073 37073 37 420 0 + 9 0.118 1.421 1836 1836 Warren 37185 37185 93 968 4 + 10 0.124 1.428 1837 1837 Stokes 37169 37169 85 1612 1 + NWBIR74 BIR79 SID79 NWBIR79 geometry + 1 10 1364 0 19 MULTIPOLYGON (((-81.47276 3... + 2 10 542 3 12 MULTIPOLYGON (((-81.23989 3... + 3 208 3616 6 260 MULTIPOLYGON (((-80.45634 3... + 4 123 830 2 145 MULTIPOLYGON (((-76.00897 3... + 5 1066 1606 3 1197 MULTIPOLYGON (((-77.21767 3... + 6 954 1838 5 1237 MULTIPOLYGON (((-76.74506 3... + 7 115 350 2 139 MULTIPOLYGON (((-76.00897 3... + 8 254 594 2 371 MULTIPOLYGON (((-76.56251 3... + 9 748 1190 2 844 MULTIPOLYGON (((-78.30876 3... + 10 160 2038 5 176 MULTIPOLYGON (((-80.02567 3... + +--- + + Code + importer_data(table = "nc", schema = "public", db = "test_datalibaba", user = "test", + limit = 4) + Output + Simple feature collection with 4 features and 14 fields + Geometry type: MULTIPOLYGON + Dimension: XY + Bounding box: xmin: -81.74107 ymin: 36.07282 xmax: -75.77316 ymax: 36.58965 + Geodetic CRS: NAD27 + AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 + 1 0.114 1.442 1825 1825 Ashe 37009 37009 5 1091 1 + 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 + 3 0.143 1.630 1828 1828 Surry 37171 37171 86 3188 5 + 4 0.070 2.968 1831 1831 Currituck 37053 37053 27 508 1 + NWBIR74 BIR79 SID79 NWBIR79 geometry + 1 10 1364 0 19 MULTIPOLYGON (((-81.47276 3... + 2 10 542 3 12 MULTIPOLYGON (((-81.23989 3... + 3 208 3616 6 260 MULTIPOLYGON (((-80.45634 3... + 4 123 830 2 145 MULTIPOLYGON (((-76.00897 3... + +--- + + Code + importer_data(table = "test_nc_noid", schema = "public", db = "test_datalibaba", + user = "test", limit = 4) + Output + Simple feature collection with 4 features and 14 fields + Geometry type: MULTIPOLYGON + Dimension: XY + Bounding box: xmin: -81.74107 ymin: 36.07282 xmax: -75.77316 ymax: 36.58965 + Geodetic CRS: NAD27 + AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 + 1 0.114 1.442 1825 1825 Ashe 37009 37009 5 1091 1 + 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 + 3 0.143 1.630 1828 1828 Surry 37171 37171 86 3188 5 + 4 0.070 2.968 1831 1831 Currituck 37053 37053 27 508 1 + NWBIR74 BIR79 SID79 NWBIR79 geometry + 1 10 1364 0 19 MULTIPOLYGON (((-81.47276 3... + 2 10 542 3 12 MULTIPOLYGON (((-81.23989 3... + 3 208 3616 6 260 MULTIPOLYGON (((-80.45634 3... + 4 123 830 2 145 MULTIPOLYGON (((-76.00897 3... + +# get_data works + + Code + get_data(con = con, schema = "public", table = "test_iris") + Output + id sepal_length sepal_width petal_length petal_width species + 1 1 5.1 3.5 1.4 0.2 setosa + 2 2 4.9 3.0 1.4 0.2 setosa + 3 3 4.7 3.2 1.3 0.2 setosa + 4 4 4.6 3.1 1.5 0.2 setosa + 5 5 5.0 3.6 1.4 0.2 setosa + 6 6 5.4 3.9 1.7 0.4 setosa + 7 7 4.6 3.4 1.4 0.3 setosa + 8 8 5.0 3.4 1.5 0.2 setosa + 9 9 4.4 2.9 1.4 0.2 setosa + 10 10 4.9 3.1 1.5 0.1 setosa + 11 11 5.4 3.7 1.5 0.2 setosa + 12 12 4.8 3.4 1.6 0.2 setosa + 13 13 4.8 3.0 1.4 0.1 setosa + 14 14 4.3 3.0 1.1 0.1 setosa + 15 15 5.8 4.0 1.2 0.2 setosa + 16 16 5.7 4.4 1.5 0.4 setosa + 17 17 5.4 3.9 1.3 0.4 setosa + 18 18 5.1 3.5 1.4 0.3 setosa + 19 19 5.7 3.8 1.7 0.3 setosa + 20 20 5.1 3.8 1.5 0.3 setosa + 21 21 5.4 3.4 1.7 0.2 setosa + 22 22 5.1 3.7 1.5 0.4 setosa + 23 23 4.6 3.6 1.0 0.2 setosa + 24 24 5.1 3.3 1.7 0.5 setosa + 25 25 4.8 3.4 1.9 0.2 setosa + 26 26 5.0 3.0 1.6 0.2 setosa + 27 27 5.0 3.4 1.6 0.4 setosa + 28 28 5.2 3.5 1.5 0.2 setosa + 29 29 5.2 3.4 1.4 0.2 setosa + 30 30 4.7 3.2 1.6 0.2 setosa + 31 31 4.8 3.1 1.6 0.2 setosa + 32 32 5.4 3.4 1.5 0.4 setosa + 33 33 5.2 4.1 1.5 0.1 setosa + 34 34 5.5 4.2 1.4 0.2 setosa + 35 35 4.9 3.1 1.5 0.2 setosa + 36 36 5.0 3.2 1.2 0.2 setosa + 37 37 5.5 3.5 1.3 0.2 setosa + 38 38 4.9 3.6 1.4 0.1 setosa + 39 39 4.4 3.0 1.3 0.2 setosa + 40 40 5.1 3.4 1.5 0.2 setosa + 41 41 5.0 3.5 1.3 0.3 setosa + 42 42 4.5 2.3 1.3 0.3 setosa + 43 43 4.4 3.2 1.3 0.2 setosa + 44 44 5.0 3.5 1.6 0.6 setosa + 45 45 5.1 3.8 1.9 0.4 setosa + 46 46 4.8 3.0 1.4 0.3 setosa + 47 47 5.1 3.8 1.6 0.2 setosa + 48 48 4.6 3.2 1.4 0.2 setosa + 49 49 5.3 3.7 1.5 0.2 setosa + 50 50 5.0 3.3 1.4 0.2 setosa + 51 51 7.0 3.2 4.7 1.4 versicolor + 52 52 6.4 3.2 4.5 1.5 versicolor + 53 53 6.9 3.1 4.9 1.5 versicolor + 54 54 5.5 2.3 4.0 1.3 versicolor + 55 55 6.5 2.8 4.6 1.5 versicolor + 56 56 5.7 2.8 4.5 1.3 versicolor + 57 57 6.3 3.3 4.7 1.6 versicolor + 58 58 4.9 2.4 3.3 1.0 versicolor + 59 59 6.6 2.9 4.6 1.3 versicolor + 60 60 5.2 2.7 3.9 1.4 versicolor + 61 61 5.0 2.0 3.5 1.0 versicolor + 62 62 5.9 3.0 4.2 1.5 versicolor + 63 63 6.0 2.2 4.0 1.0 versicolor + 64 64 6.1 2.9 4.7 1.4 versicolor + 65 65 5.6 2.9 3.6 1.3 versicolor + 66 66 6.7 3.1 4.4 1.4 versicolor + 67 67 5.6 3.0 4.5 1.5 versicolor + 68 68 5.8 2.7 4.1 1.0 versicolor + 69 69 6.2 2.2 4.5 1.5 versicolor + 70 70 5.6 2.5 3.9 1.1 versicolor + 71 71 5.9 3.2 4.8 1.8 versicolor + 72 72 6.1 2.8 4.0 1.3 versicolor + 73 73 6.3 2.5 4.9 1.5 versicolor + 74 74 6.1 2.8 4.7 1.2 versicolor + 75 75 6.4 2.9 4.3 1.3 versicolor + 76 76 6.6 3.0 4.4 1.4 versicolor + 77 77 6.8 2.8 4.8 1.4 versicolor + 78 78 6.7 3.0 5.0 1.7 versicolor + 79 79 6.0 2.9 4.5 1.5 versicolor + 80 80 5.7 2.6 3.5 1.0 versicolor + 81 81 5.5 2.4 3.8 1.1 versicolor + 82 82 5.5 2.4 3.7 1.0 versicolor + 83 83 5.8 2.7 3.9 1.2 versicolor + 84 84 6.0 2.7 5.1 1.6 versicolor + 85 85 5.4 3.0 4.5 1.5 versicolor + 86 86 6.0 3.4 4.5 1.6 versicolor + 87 87 6.7 3.1 4.7 1.5 versicolor + 88 88 6.3 2.3 4.4 1.3 versicolor + 89 89 5.6 3.0 4.1 1.3 versicolor + 90 90 5.5 2.5 4.0 1.3 versicolor + 91 91 5.5 2.6 4.4 1.2 versicolor + 92 92 6.1 3.0 4.6 1.4 versicolor + 93 93 5.8 2.6 4.0 1.2 versicolor + 94 94 5.0 2.3 3.3 1.0 versicolor + 95 95 5.6 2.7 4.2 1.3 versicolor + 96 96 5.7 3.0 4.2 1.2 versicolor + 97 97 5.7 2.9 4.2 1.3 versicolor + 98 98 6.2 2.9 4.3 1.3 versicolor + 99 99 5.1 2.5 3.0 1.1 versicolor + 100 100 5.7 2.8 4.1 1.3 versicolor + 101 101 6.3 3.3 6.0 2.5 virginica + 102 102 5.8 2.7 5.1 1.9 virginica + 103 103 7.1 3.0 5.9 2.1 virginica + 104 104 6.3 2.9 5.6 1.8 virginica + 105 105 6.5 3.0 5.8 2.2 virginica + 106 106 7.6 3.0 6.6 2.1 virginica + 107 107 4.9 2.5 4.5 1.7 virginica + 108 108 7.3 2.9 6.3 1.8 virginica + 109 109 6.7 2.5 5.8 1.8 virginica + 110 110 7.2 3.6 6.1 2.5 virginica + 111 111 6.5 3.2 5.1 2.0 virginica + 112 112 6.4 2.7 5.3 1.9 virginica + 113 113 6.8 3.0 5.5 2.1 virginica + 114 114 5.7 2.5 5.0 2.0 virginica + 115 115 5.8 2.8 5.1 2.4 virginica + 116 116 6.4 3.2 5.3 2.3 virginica + 117 117 6.5 3.0 5.5 1.8 virginica + 118 118 7.7 3.8 6.7 2.2 virginica + 119 119 7.7 2.6 6.9 2.3 virginica + 120 120 6.0 2.2 5.0 1.5 virginica + 121 121 6.9 3.2 5.7 2.3 virginica + 122 122 5.6 2.8 4.9 2.0 virginica + 123 123 7.7 2.8 6.7 2.0 virginica + 124 124 6.3 2.7 4.9 1.8 virginica + 125 125 6.7 3.3 5.7 2.1 virginica + 126 126 7.2 3.2 6.0 1.8 virginica + 127 127 6.2 2.8 4.8 1.8 virginica + 128 128 6.1 3.0 4.9 1.8 virginica + 129 129 6.4 2.8 5.6 2.1 virginica + 130 130 7.2 3.0 5.8 1.6 virginica + 131 131 7.4 2.8 6.1 1.9 virginica + 132 132 7.9 3.8 6.4 2.0 virginica + 133 133 6.4 2.8 5.6 2.2 virginica + 134 134 6.3 2.8 5.1 1.5 virginica + 135 135 6.1 2.6 5.6 1.4 virginica + 136 136 7.7 3.0 6.1 2.3 virginica + 137 137 6.3 3.4 5.6 2.4 virginica + 138 138 6.4 3.1 5.5 1.8 virginica + 139 139 6.0 3.0 4.8 1.8 virginica + 140 140 6.9 3.1 5.4 2.1 virginica + 141 141 6.7 3.1 5.6 2.4 virginica + 142 142 6.9 3.1 5.1 2.3 virginica + 143 143 5.8 2.7 5.1 1.9 virginica + 144 144 6.8 3.2 5.9 2.3 virginica + 145 145 6.7 3.3 5.7 2.5 virginica + 146 146 6.7 3.0 5.2 2.3 virginica + 147 147 6.3 2.5 5.0 1.9 virginica + 148 148 6.5 3.0 5.2 2.0 virginica + 149 149 6.2 3.4 5.4 2.3 virginica + 150 150 5.9 3.0 5.1 1.8 virginica + todate r_row_names__ + 1 2025-02-27 15:29:32 1 + 2 2025-02-27 15:29:32 2 + 3 2025-02-27 15:29:32 3 + 4 2025-02-27 15:29:32 4 + 5 2025-02-27 15:29:32 5 + 6 2025-02-27 15:29:32 6 + 7 2025-02-27 15:29:32 7 + 8 2025-02-27 15:29:32 8 + 9 2025-02-27 15:29:32 9 + 10 2025-02-27 15:29:32 10 + 11 2025-02-27 15:29:32 11 + 12 2025-02-27 15:29:32 12 + 13 2025-02-27 15:29:32 13 + 14 2025-02-27 15:29:32 14 + 15 2025-02-27 15:29:32 15 + 16 2025-02-27 15:29:32 16 + 17 2025-02-27 15:29:32 17 + 18 2025-02-27 15:29:32 18 + 19 2025-02-27 15:29:32 19 + 20 2025-02-27 15:29:32 20 + 21 2025-02-27 15:29:32 21 + 22 2025-02-27 15:29:32 22 + 23 2025-02-27 15:29:32 23 + 24 2025-02-27 15:29:32 24 + 25 2025-02-27 15:29:32 25 + 26 2025-02-27 15:29:32 26 + 27 2025-02-27 15:29:32 27 + 28 2025-02-27 15:29:32 28 + 29 2025-02-27 15:29:32 29 + 30 2025-02-27 15:29:32 30 + 31 2025-02-27 15:29:32 31 + 32 2025-02-27 15:29:32 32 + 33 2025-02-27 15:29:32 33 + 34 2025-02-27 15:29:32 34 + 35 2025-02-27 15:29:32 35 + 36 2025-02-27 15:29:32 36 + 37 2025-02-27 15:29:32 37 + 38 2025-02-27 15:29:32 38 + 39 2025-02-27 15:29:32 39 + 40 2025-02-27 15:29:32 40 + 41 2025-02-27 15:29:32 41 + 42 2025-02-27 15:29:32 42 + 43 2025-02-27 15:29:32 43 + 44 2025-02-27 15:29:32 44 + 45 2025-02-27 15:29:32 45 + 46 2025-02-27 15:29:32 46 + 47 2025-02-27 15:29:32 47 + 48 2025-02-27 15:29:32 48 + 49 2025-02-27 15:29:32 49 + 50 2025-02-27 15:29:32 50 + 51 2025-02-27 15:29:32 51 + 52 2025-02-27 15:29:32 52 + 53 2025-02-27 15:29:32 53 + 54 2025-02-27 15:29:32 54 + 55 2025-02-27 15:29:32 55 + 56 2025-02-27 15:29:32 56 + 57 2025-02-27 15:29:32 57 + 58 2025-02-27 15:29:32 58 + 59 2025-02-27 15:29:32 59 + 60 2025-02-27 15:29:32 60 + 61 2025-02-27 15:29:32 61 + 62 2025-02-27 15:29:32 62 + 63 2025-02-27 15:29:32 63 + 64 2025-02-27 15:29:32 64 + 65 2025-02-27 15:29:32 65 + 66 2025-02-27 15:29:32 66 + 67 2025-02-27 15:29:32 67 + 68 2025-02-27 15:29:32 68 + 69 2025-02-27 15:29:32 69 + 70 2025-02-27 15:29:32 70 + 71 2025-02-27 15:29:32 71 + 72 2025-02-27 15:29:32 72 + 73 2025-02-27 15:29:32 73 + 74 2025-02-27 15:29:32 74 + 75 2025-02-27 15:29:32 75 + 76 2025-02-27 15:29:32 76 + 77 2025-02-27 15:29:32 77 + 78 2025-02-27 15:29:32 78 + 79 2025-02-27 15:29:32 79 + 80 2025-02-27 15:29:32 80 + 81 2025-02-27 15:29:32 81 + 82 2025-02-27 15:29:32 82 + 83 2025-02-27 15:29:32 83 + 84 2025-02-27 15:29:32 84 + 85 2025-02-27 15:29:32 85 + 86 2025-02-27 15:29:32 86 + 87 2025-02-27 15:29:32 87 + 88 2025-02-27 15:29:32 88 + 89 2025-02-27 15:29:32 89 + 90 2025-02-27 15:29:32 90 + 91 2025-02-27 15:29:32 91 + 92 2025-02-27 15:29:32 92 + 93 2025-02-27 15:29:32 93 + 94 2025-02-27 15:29:32 94 + 95 2025-02-27 15:29:32 95 + 96 2025-02-27 15:29:32 96 + 97 2025-02-27 15:29:32 97 + 98 2025-02-27 15:29:32 98 + 99 2025-02-27 15:29:32 99 + 100 2025-02-27 15:29:32 100 + 101 2025-02-27 15:29:32 101 + 102 2025-02-27 15:29:32 102 + 103 2025-02-27 15:29:32 103 + 104 2025-02-27 15:29:32 104 + 105 2025-02-27 15:29:32 105 + 106 2025-02-27 15:29:32 106 + 107 2025-02-27 15:29:32 107 + 108 2025-02-27 15:29:32 108 + 109 2025-02-27 15:29:32 109 + 110 2025-02-27 15:29:32 110 + 111 2025-02-27 15:29:32 111 + 112 2025-02-27 15:29:32 112 + 113 2025-02-27 15:29:32 113 + 114 2025-02-27 15:29:32 114 + 115 2025-02-27 15:29:32 115 + 116 2025-02-27 15:29:32 116 + 117 2025-02-27 15:29:32 117 + 118 2025-02-27 15:29:32 118 + 119 2025-02-27 15:29:32 119 + 120 2025-02-27 15:29:32 120 + 121 2025-02-27 15:29:32 121 + 122 2025-02-27 15:29:32 122 + 123 2025-02-27 15:29:32 123 + 124 2025-02-27 15:29:32 124 + 125 2025-02-27 15:29:32 125 + 126 2025-02-27 15:29:32 126 + 127 2025-02-27 15:29:32 127 + 128 2025-02-27 15:29:32 128 + 129 2025-02-27 15:29:32 129 + 130 2025-02-27 15:29:32 130 + 131 2025-02-27 15:29:32 131 + 132 2025-02-27 15:29:32 132 + 133 2025-02-27 15:29:32 133 + 134 2025-02-27 15:29:32 134 + 135 2025-02-27 15:29:32 135 + 136 2025-02-27 15:29:32 136 + 137 2025-02-27 15:29:32 137 + 138 2025-02-27 15:29:32 138 + 139 2025-02-27 15:29:32 139 + 140 2025-02-27 15:29:32 140 + 141 2025-02-27 15:29:32 141 + 142 2025-02-27 15:29:32 142 + 143 2025-02-27 15:29:32 143 + 144 2025-02-27 15:29:32 144 + 145 2025-02-27 15:29:32 145 + 146 2025-02-27 15:29:32 146 + 147 2025-02-27 15:29:32 147 + 148 2025-02-27 15:29:32 148 + 149 2025-02-27 15:29:32 149 + 150 2025-02-27 15:29:32 150 + +# get_data_dbi works + + Code + get_data_dbi(con = con, schema = "public", table = "test_iris") + Output + id sepal_length sepal_width petal_length petal_width species + 1 1 5.1 3.5 1.4 0.2 setosa + 2 2 4.9 3.0 1.4 0.2 setosa + 3 3 4.7 3.2 1.3 0.2 setosa + 4 4 4.6 3.1 1.5 0.2 setosa + 5 5 5.0 3.6 1.4 0.2 setosa + 6 6 5.4 3.9 1.7 0.4 setosa + 7 7 4.6 3.4 1.4 0.3 setosa + 8 8 5.0 3.4 1.5 0.2 setosa + 9 9 4.4 2.9 1.4 0.2 setosa + 10 10 4.9 3.1 1.5 0.1 setosa + 11 11 5.4 3.7 1.5 0.2 setosa + 12 12 4.8 3.4 1.6 0.2 setosa + 13 13 4.8 3.0 1.4 0.1 setosa + 14 14 4.3 3.0 1.1 0.1 setosa + 15 15 5.8 4.0 1.2 0.2 setosa + 16 16 5.7 4.4 1.5 0.4 setosa + 17 17 5.4 3.9 1.3 0.4 setosa + 18 18 5.1 3.5 1.4 0.3 setosa + 19 19 5.7 3.8 1.7 0.3 setosa + 20 20 5.1 3.8 1.5 0.3 setosa + 21 21 5.4 3.4 1.7 0.2 setosa + 22 22 5.1 3.7 1.5 0.4 setosa + 23 23 4.6 3.6 1.0 0.2 setosa + 24 24 5.1 3.3 1.7 0.5 setosa + 25 25 4.8 3.4 1.9 0.2 setosa + 26 26 5.0 3.0 1.6 0.2 setosa + 27 27 5.0 3.4 1.6 0.4 setosa + 28 28 5.2 3.5 1.5 0.2 setosa + 29 29 5.2 3.4 1.4 0.2 setosa + 30 30 4.7 3.2 1.6 0.2 setosa + 31 31 4.8 3.1 1.6 0.2 setosa + 32 32 5.4 3.4 1.5 0.4 setosa + 33 33 5.2 4.1 1.5 0.1 setosa + 34 34 5.5 4.2 1.4 0.2 setosa + 35 35 4.9 3.1 1.5 0.2 setosa + 36 36 5.0 3.2 1.2 0.2 setosa + 37 37 5.5 3.5 1.3 0.2 setosa + 38 38 4.9 3.6 1.4 0.1 setosa + 39 39 4.4 3.0 1.3 0.2 setosa + 40 40 5.1 3.4 1.5 0.2 setosa + 41 41 5.0 3.5 1.3 0.3 setosa + 42 42 4.5 2.3 1.3 0.3 setosa + 43 43 4.4 3.2 1.3 0.2 setosa + 44 44 5.0 3.5 1.6 0.6 setosa + 45 45 5.1 3.8 1.9 0.4 setosa + 46 46 4.8 3.0 1.4 0.3 setosa + 47 47 5.1 3.8 1.6 0.2 setosa + 48 48 4.6 3.2 1.4 0.2 setosa + 49 49 5.3 3.7 1.5 0.2 setosa + 50 50 5.0 3.3 1.4 0.2 setosa + 51 51 7.0 3.2 4.7 1.4 versicolor + 52 52 6.4 3.2 4.5 1.5 versicolor + 53 53 6.9 3.1 4.9 1.5 versicolor + 54 54 5.5 2.3 4.0 1.3 versicolor + 55 55 6.5 2.8 4.6 1.5 versicolor + 56 56 5.7 2.8 4.5 1.3 versicolor + 57 57 6.3 3.3 4.7 1.6 versicolor + 58 58 4.9 2.4 3.3 1.0 versicolor + 59 59 6.6 2.9 4.6 1.3 versicolor + 60 60 5.2 2.7 3.9 1.4 versicolor + 61 61 5.0 2.0 3.5 1.0 versicolor + 62 62 5.9 3.0 4.2 1.5 versicolor + 63 63 6.0 2.2 4.0 1.0 versicolor + 64 64 6.1 2.9 4.7 1.4 versicolor + 65 65 5.6 2.9 3.6 1.3 versicolor + 66 66 6.7 3.1 4.4 1.4 versicolor + 67 67 5.6 3.0 4.5 1.5 versicolor + 68 68 5.8 2.7 4.1 1.0 versicolor + 69 69 6.2 2.2 4.5 1.5 versicolor + 70 70 5.6 2.5 3.9 1.1 versicolor + 71 71 5.9 3.2 4.8 1.8 versicolor + 72 72 6.1 2.8 4.0 1.3 versicolor + 73 73 6.3 2.5 4.9 1.5 versicolor + 74 74 6.1 2.8 4.7 1.2 versicolor + 75 75 6.4 2.9 4.3 1.3 versicolor + 76 76 6.6 3.0 4.4 1.4 versicolor + 77 77 6.8 2.8 4.8 1.4 versicolor + 78 78 6.7 3.0 5.0 1.7 versicolor + 79 79 6.0 2.9 4.5 1.5 versicolor + 80 80 5.7 2.6 3.5 1.0 versicolor + 81 81 5.5 2.4 3.8 1.1 versicolor + 82 82 5.5 2.4 3.7 1.0 versicolor + 83 83 5.8 2.7 3.9 1.2 versicolor + 84 84 6.0 2.7 5.1 1.6 versicolor + 85 85 5.4 3.0 4.5 1.5 versicolor + 86 86 6.0 3.4 4.5 1.6 versicolor + 87 87 6.7 3.1 4.7 1.5 versicolor + 88 88 6.3 2.3 4.4 1.3 versicolor + 89 89 5.6 3.0 4.1 1.3 versicolor + 90 90 5.5 2.5 4.0 1.3 versicolor + 91 91 5.5 2.6 4.4 1.2 versicolor + 92 92 6.1 3.0 4.6 1.4 versicolor + 93 93 5.8 2.6 4.0 1.2 versicolor + 94 94 5.0 2.3 3.3 1.0 versicolor + 95 95 5.6 2.7 4.2 1.3 versicolor + 96 96 5.7 3.0 4.2 1.2 versicolor + 97 97 5.7 2.9 4.2 1.3 versicolor + 98 98 6.2 2.9 4.3 1.3 versicolor + 99 99 5.1 2.5 3.0 1.1 versicolor + 100 100 5.7 2.8 4.1 1.3 versicolor + 101 101 6.3 3.3 6.0 2.5 virginica + 102 102 5.8 2.7 5.1 1.9 virginica + 103 103 7.1 3.0 5.9 2.1 virginica + 104 104 6.3 2.9 5.6 1.8 virginica + 105 105 6.5 3.0 5.8 2.2 virginica + 106 106 7.6 3.0 6.6 2.1 virginica + 107 107 4.9 2.5 4.5 1.7 virginica + 108 108 7.3 2.9 6.3 1.8 virginica + 109 109 6.7 2.5 5.8 1.8 virginica + 110 110 7.2 3.6 6.1 2.5 virginica + 111 111 6.5 3.2 5.1 2.0 virginica + 112 112 6.4 2.7 5.3 1.9 virginica + 113 113 6.8 3.0 5.5 2.1 virginica + 114 114 5.7 2.5 5.0 2.0 virginica + 115 115 5.8 2.8 5.1 2.4 virginica + 116 116 6.4 3.2 5.3 2.3 virginica + 117 117 6.5 3.0 5.5 1.8 virginica + 118 118 7.7 3.8 6.7 2.2 virginica + 119 119 7.7 2.6 6.9 2.3 virginica + 120 120 6.0 2.2 5.0 1.5 virginica + 121 121 6.9 3.2 5.7 2.3 virginica + 122 122 5.6 2.8 4.9 2.0 virginica + 123 123 7.7 2.8 6.7 2.0 virginica + 124 124 6.3 2.7 4.9 1.8 virginica + 125 125 6.7 3.3 5.7 2.1 virginica + 126 126 7.2 3.2 6.0 1.8 virginica + 127 127 6.2 2.8 4.8 1.8 virginica + 128 128 6.1 3.0 4.9 1.8 virginica + 129 129 6.4 2.8 5.6 2.1 virginica + 130 130 7.2 3.0 5.8 1.6 virginica + 131 131 7.4 2.8 6.1 1.9 virginica + 132 132 7.9 3.8 6.4 2.0 virginica + 133 133 6.4 2.8 5.6 2.2 virginica + 134 134 6.3 2.8 5.1 1.5 virginica + 135 135 6.1 2.6 5.6 1.4 virginica + 136 136 7.7 3.0 6.1 2.3 virginica + 137 137 6.3 3.4 5.6 2.4 virginica + 138 138 6.4 3.1 5.5 1.8 virginica + 139 139 6.0 3.0 4.8 1.8 virginica + 140 140 6.9 3.1 5.4 2.1 virginica + 141 141 6.7 3.1 5.6 2.4 virginica + 142 142 6.9 3.1 5.1 2.3 virginica + 143 143 5.8 2.7 5.1 1.9 virginica + 144 144 6.8 3.2 5.9 2.3 virginica + 145 145 6.7 3.3 5.7 2.5 virginica + 146 146 6.7 3.0 5.2 2.3 virginica + 147 147 6.3 2.5 5.0 1.9 virginica + 148 148 6.5 3.0 5.2 2.0 virginica + 149 149 6.2 3.4 5.4 2.3 virginica + 150 150 5.9 3.0 5.1 1.8 virginica + todate r_row_names__ + 1 2025-02-27 14:29:32 1 + 2 2025-02-27 14:29:32 2 + 3 2025-02-27 14:29:32 3 + 4 2025-02-27 14:29:32 4 + 5 2025-02-27 14:29:32 5 + 6 2025-02-27 14:29:32 6 + 7 2025-02-27 14:29:32 7 + 8 2025-02-27 14:29:32 8 + 9 2025-02-27 14:29:32 9 + 10 2025-02-27 14:29:32 10 + 11 2025-02-27 14:29:32 11 + 12 2025-02-27 14:29:32 12 + 13 2025-02-27 14:29:32 13 + 14 2025-02-27 14:29:32 14 + 15 2025-02-27 14:29:32 15 + 16 2025-02-27 14:29:32 16 + 17 2025-02-27 14:29:32 17 + 18 2025-02-27 14:29:32 18 + 19 2025-02-27 14:29:32 19 + 20 2025-02-27 14:29:32 20 + 21 2025-02-27 14:29:32 21 + 22 2025-02-27 14:29:32 22 + 23 2025-02-27 14:29:32 23 + 24 2025-02-27 14:29:32 24 + 25 2025-02-27 14:29:32 25 + 26 2025-02-27 14:29:32 26 + 27 2025-02-27 14:29:32 27 + 28 2025-02-27 14:29:32 28 + 29 2025-02-27 14:29:32 29 + 30 2025-02-27 14:29:32 30 + 31 2025-02-27 14:29:32 31 + 32 2025-02-27 14:29:32 32 + 33 2025-02-27 14:29:32 33 + 34 2025-02-27 14:29:32 34 + 35 2025-02-27 14:29:32 35 + 36 2025-02-27 14:29:32 36 + 37 2025-02-27 14:29:32 37 + 38 2025-02-27 14:29:32 38 + 39 2025-02-27 14:29:32 39 + 40 2025-02-27 14:29:32 40 + 41 2025-02-27 14:29:32 41 + 42 2025-02-27 14:29:32 42 + 43 2025-02-27 14:29:32 43 + 44 2025-02-27 14:29:32 44 + 45 2025-02-27 14:29:32 45 + 46 2025-02-27 14:29:32 46 + 47 2025-02-27 14:29:32 47 + 48 2025-02-27 14:29:32 48 + 49 2025-02-27 14:29:32 49 + 50 2025-02-27 14:29:32 50 + 51 2025-02-27 14:29:32 51 + 52 2025-02-27 14:29:32 52 + 53 2025-02-27 14:29:32 53 + 54 2025-02-27 14:29:32 54 + 55 2025-02-27 14:29:32 55 + 56 2025-02-27 14:29:32 56 + 57 2025-02-27 14:29:32 57 + 58 2025-02-27 14:29:32 58 + 59 2025-02-27 14:29:32 59 + 60 2025-02-27 14:29:32 60 + 61 2025-02-27 14:29:32 61 + 62 2025-02-27 14:29:32 62 + 63 2025-02-27 14:29:32 63 + 64 2025-02-27 14:29:32 64 + 65 2025-02-27 14:29:32 65 + 66 2025-02-27 14:29:32 66 + 67 2025-02-27 14:29:32 67 + 68 2025-02-27 14:29:32 68 + 69 2025-02-27 14:29:32 69 + 70 2025-02-27 14:29:32 70 + 71 2025-02-27 14:29:32 71 + 72 2025-02-27 14:29:32 72 + 73 2025-02-27 14:29:32 73 + 74 2025-02-27 14:29:32 74 + 75 2025-02-27 14:29:32 75 + 76 2025-02-27 14:29:32 76 + 77 2025-02-27 14:29:32 77 + 78 2025-02-27 14:29:32 78 + 79 2025-02-27 14:29:32 79 + 80 2025-02-27 14:29:32 80 + 81 2025-02-27 14:29:32 81 + 82 2025-02-27 14:29:32 82 + 83 2025-02-27 14:29:32 83 + 84 2025-02-27 14:29:32 84 + 85 2025-02-27 14:29:32 85 + 86 2025-02-27 14:29:32 86 + 87 2025-02-27 14:29:32 87 + 88 2025-02-27 14:29:32 88 + 89 2025-02-27 14:29:32 89 + 90 2025-02-27 14:29:32 90 + 91 2025-02-27 14:29:32 91 + 92 2025-02-27 14:29:32 92 + 93 2025-02-27 14:29:32 93 + 94 2025-02-27 14:29:32 94 + 95 2025-02-27 14:29:32 95 + 96 2025-02-27 14:29:32 96 + 97 2025-02-27 14:29:32 97 + 98 2025-02-27 14:29:32 98 + 99 2025-02-27 14:29:32 99 + 100 2025-02-27 14:29:32 100 + 101 2025-02-27 14:29:32 101 + 102 2025-02-27 14:29:32 102 + 103 2025-02-27 14:29:32 103 + 104 2025-02-27 14:29:32 104 + 105 2025-02-27 14:29:32 105 + 106 2025-02-27 14:29:32 106 + 107 2025-02-27 14:29:32 107 + 108 2025-02-27 14:29:32 108 + 109 2025-02-27 14:29:32 109 + 110 2025-02-27 14:29:32 110 + 111 2025-02-27 14:29:32 111 + 112 2025-02-27 14:29:32 112 + 113 2025-02-27 14:29:32 113 + 114 2025-02-27 14:29:32 114 + 115 2025-02-27 14:29:32 115 + 116 2025-02-27 14:29:32 116 + 117 2025-02-27 14:29:32 117 + 118 2025-02-27 14:29:32 118 + 119 2025-02-27 14:29:32 119 + 120 2025-02-27 14:29:32 120 + 121 2025-02-27 14:29:32 121 + 122 2025-02-27 14:29:32 122 + 123 2025-02-27 14:29:32 123 + 124 2025-02-27 14:29:32 124 + 125 2025-02-27 14:29:32 125 + 126 2025-02-27 14:29:32 126 + 127 2025-02-27 14:29:32 127 + 128 2025-02-27 14:29:32 128 + 129 2025-02-27 14:29:32 129 + 130 2025-02-27 14:29:32 130 + 131 2025-02-27 14:29:32 131 + 132 2025-02-27 14:29:32 132 + 133 2025-02-27 14:29:32 133 + 134 2025-02-27 14:29:32 134 + 135 2025-02-27 14:29:32 135 + 136 2025-02-27 14:29:32 136 + 137 2025-02-27 14:29:32 137 + 138 2025-02-27 14:29:32 138 + 139 2025-02-27 14:29:32 139 + 140 2025-02-27 14:29:32 140 + 141 2025-02-27 14:29:32 141 + 142 2025-02-27 14:29:32 142 + 143 2025-02-27 14:29:32 143 + 144 2025-02-27 14:29:32 144 + 145 2025-02-27 14:29:32 145 + 146 2025-02-27 14:29:32 146 + 147 2025-02-27 14:29:32 147 + 148 2025-02-27 14:29:32 148 + 149 2025-02-27 14:29:32 149 + 150 2025-02-27 14:29:32 150 + diff --git a/tests/testthat/_snaps/6-comment_db.md b/tests/testthat/_snaps/6-comment_db.md new file mode 100644 index 0000000000000000000000000000000000000000..a16b5276046d10110ddf4ec6d6d2ad71264cf5ca --- /dev/null +++ b/tests/testthat/_snaps/6-comment_db.md @@ -0,0 +1,18 @@ +# get_db_comment works + + Code + get_db_comment(db = "test_datalibaba", user = "test", server = Sys.getenv( + "server")) + Output + [1] nom_base commentaire + <0 rows> (or 0-length row.names) + +# get_schema_comment works + + Code + get_schema_comment(schema = "public", db = "test_datalibaba", user = "test", + server = Sys.getenv("server")) + Output + nom_schema commentaire + 1 public le schema des tests qui restent ! + diff --git a/tests/testthat/_snaps/7-commenter_champs.md b/tests/testthat/_snaps/7-commenter_champs.md new file mode 100644 index 0000000000000000000000000000000000000000..c84818ec9fb39f71d90eb6f5e32a5e97796bfd71 --- /dev/null +++ b/tests/testthat/_snaps/7-commenter_champs.md @@ -0,0 +1,32 @@ +# get_cols_comment works + + Code + get_cols_comment(table = "test_iris", schema = "public", db = "test_datalibaba", + user = "test", server = Sys.getenv("server")) + Output + nom_schema nom_table nom_col commentaire + 1 public test_iris species Commentlibaba ! + +# get_table_comments works + + Code + get_table_comments(table = "retest_iris", schema = "public", db = "test_datalibaba", + user = "test", server = Sys.getenv("server")) + Output + nom_schema nom_table commentaire nom_col + 1 public retest_iris <NA> <NA> + 2 public retest_iris libellé de Sepal.Length cc Sepal.Length + 3 public retest_iris libellé de Sepal.Width cc Sepal.Width + 4 public retest_iris libellé de Petal.Length cc Petal.Length + 5 public retest_iris libellé de Petal.Width cc Petal.Width + 6 public retest_iris libellé de Species cc Species + +# get_table_comment works + + Code + get_table_comment(table = "retest_iris", schema = "public", db = "test_datalibaba", + user = "test", server = Sys.getenv("server")) + Output + nom_schema nom_table commentaire + 1 public retest_iris <NA> + diff --git a/tests/testthat/test-1-connect_to_db.R b/tests/testthat/test-1-connect_to_db.R new file mode 100644 index 0000000000000000000000000000000000000000..8c23cddf246307cdddd89301ace7414ba718c96b --- /dev/null +++ b/tests/testthat/test-1-connect_to_db.R @@ -0,0 +1,78 @@ +library(DBI) +library(odbc) +library(glue) + +test_that("connect_to_db works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + expect_true(identical(class(connect_to_db(db = "test_datalibaba", user = "test", ecoSQL = FALSE))[[1]], "PostgreSQLConnection")) + + con<- DBI::dbConnect(DBI::dbDriver("PostgreSQL"), + dbname="test_datalibaba", + host=Sys.getenv("server"), + port=Sys.getenv("port"), + user=Sys.getenv("user_test"), + password=Sys.getenv("pwd_test")) + expect_equal( + str(connect_to_db(db = "test_datalibaba", user = "test", ecoSQL = FALSE)), + str(con) + ) + + expect_true(identical(class(connect_to_db(db = "test_datalibaba", user = "test"))[[1]], "PqConnection")) + con<- DBI::dbConnect(RPostgres::Postgres(), + dbname="test_datalibaba", + host=Sys.getenv("server"), + port=Sys.getenv("port"), + user=Sys.getenv("user_test"), + password=Sys.getenv("pwd_test")) + expect_equal( + str(connect_to_db(db = "test_datalibaba", user = "test")), + str(con) + ) + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("connect_to_dbi works", { + listdriver<-odbc::odbcListDrivers() + print("test connect_to_dbi : list driver odbc") + print(listdriver) + Sys.setenv(port="5432") + Sys.setenv(server="127.0.0.1") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + patterndriver <-"^Postgre.*UNICODE|Unicode.*" + drv_unicode_postgres <- listdriver$name[grep(patterndriver, listdriver$name)][1] + con_chaine <- glue::glue("Driver={",drv_unicode_postgres,"};Server=$Sys.getenv('server')$;Database=test_datalibaba;Uid=$Sys.getenv('user_test')$;Pwd=$Sys.getenv('pwd_test')$;Port=$Sys.getenv('port')$;", + .open = "$", + .close= "$") + if(DBI::dbCanConnect(odbc::odbc(), .connection_string = con_chaine, timeout = 10, encoding = "UTF-8")){ + + expect_error(connect_to_dbi(db = "test_datalibaba", user = "test", driver="Mysql"), + "The driver must be NULL or 'PostgreSQL'") + expect_error(connect_to_dbi(db = "test_datalibaba", user = "test", driver=NULL), + "alert: Pas de driver Postgresql pour ODBC") + + expect_true(identical(class(connect_to_dbi(db = "test_datalibaba", user = "test"))[[1]], "PostgreSQL")) + + con <- DBI::dbConnect(odbc::odbc(), + .connection_string = con_chaine, + timeout = 10, + encoding = "UTF-8") + expect_equal( + str(connect_to_dbi(db = "test_datalibaba", user = "test")), + str(con) + ) + }else{ + print(DBI::dbCanConnect(odbc::odbc(), .connection_string = con_chaine, timeout = 10, encoding = "UTF-8")) + print('warning: connect_to_dbi - local database postgresql doesnt work with odbc !') + expect_equal(1,1) + } +}) diff --git a/tests/testthat/test-2-check_server_renviron.R b/tests/testthat/test-2-check_server_renviron.R new file mode 100644 index 0000000000000000000000000000000000000000..1688095a8cf36d7f0f7320665902f7cbcc807a51 --- /dev/null +++ b/tests/testthat/test-2-check_server_renviron.R @@ -0,0 +1,46 @@ +library(fs) +test_that("scoped_path_r works", { + + expect_error(scoped_path_r(scope="other"), + "'arg' should be one of") + + Sys.setenv(R_ENVIRON_USER="~") + res<-fs::path_expand("~") + expect_equal(scoped_path_r("user", envvar = "R_ENVIRON_USER"), res) + + res<-fs::path(usethis::proj_get(), "README.md") + expect_equal(scoped_path_r("project", "README.md"),res) + +}) + +test_that("check_server_renviron works", { + + Sys.setenv(R_ENVIRON_USER="~/test-toto") + expect_message(check_server_renviron(), + paste0("x .Renviron : le fichier ",scoped_path_r("user", ".Renviron", envvar = "R_ENVIRON_USER")," n'existe pas")) + + Sys.setenv(R_ENVIRON_USER="~") + if (.Platform$OS.type != "windows" & !file.exists(scoped_path_r("user", ".Renviron", envvar = "R_ENVIRON_USER"))) { + file.create(scoped_path_r("user", ".Renviron", envvar = "R_ENVIRON_USER")) + } + + Sys.setenv(server="") + Sys.setenv(port="") + Sys.setenv(user_does="") + Sys.setenv(pwd_does="") + expect_message(check_server_renviron(), paste0("i v\u00e9rification de la configuration des variables syst\u00e8me \u00e0 l'adresse ",scoped_path_r("user", ".Renviron", envvar = "R_ENVIRON_USER"),".")) + expect_message(check_server_renviron(), "* .Renviron : la variable server n'est pas d\u00e9finie.") + expect_message(check_server_renviron(), "* .Renviron : la variable port n'est pas d\u00e9finie.") + expect_message(check_server_renviron(), "* .Renviron : la variable user_does n'est pas d\u00e9finie.") + expect_message(check_server_renviron(), "* .Renviron : la variable pwd_does n'est pas d\u00e9finie.") + + Sys.setenv(server="127.0.0.1") + Sys.setenv(port="5432") + Sys.setenv(user_does="runner") + Sys.setenv(pwd_does=Sys.getenv("BDD_RUNNER_PWD")) + + expect_message(check_server_renviron(), paste0("v .Renviron : la variable server est d\u00e9finie avec la valeur ",Sys.getenv('server'))) + expect_message(check_server_renviron(), paste0("v .Renviron : la variable port est d\u00e9finie avec la valeur ",Sys.getenv('port'))) + expect_message(check_server_renviron(), paste0("v .Renviron : la variable user_does est d\u00e9finie avec la valeur ",Sys.getenv('user_does'))) + expect_message(check_server_renviron(), paste0("v .Renviron : la variable pwd_does est d\u00e9finie avec la valeur ",Sys.getenv('pwd_does'))) +}) diff --git a/tests/testthat/test-3-utilitaires.R b/tests/testthat/test-3-utilitaires.R new file mode 100644 index 0000000000000000000000000000000000000000..1194956c2d325ddda53ece2eca351c171d2ccade --- /dev/null +++ b/tests/testthat/test-3-utilitaires.R @@ -0,0 +1,4 @@ +test_that("standard_var_pg works", { + expect_equal(standard_var_pg("%Nom@fichier$test8pour(standard_var_pg!"), + "_nom_fichier_test8pour_standard_var_pg_") +}) diff --git a/tests/testthat/test-4-post_data.R b/tests/testthat/test-4-post_data.R new file mode 100644 index 0000000000000000000000000000000000000000..c6ebc425ee4f43c3cc2b5a2501e369ab059ae06c --- /dev/null +++ b/tests/testthat/test-4-post_data.R @@ -0,0 +1,140 @@ +library(DBI) +library(magrittr) +library(tibble) +library(lubridate) +library(dplyr) +library(sf) +library(glue) +library(backports) + +test_that("poster_data works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + # test list_tables (utilise dans poster_data) + schem <- paste0("test_listdata_",sample.int(1000, 1)) + condirect <- DBI::dbConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="test_datalibaba") + DBI::dbExecute(condirect, paste0("CREATE SCHEMA ",schem," AUTHORIZATION runner;")) + DBI::dbExecute(condirect, paste0("GRANT ALL ON SCHEMA ",schem," TO runner WITH GRANT OPTION;")) + DBI::dbExecute(condirect, paste0("ALTER DEFAULT PRIVILEGES IN SCHEMA ",schem," GRANT ALL ON TABLES TO runner;")) + DBI::dbExecute(condirect, paste0("ALTER DEFAULT PRIVILEGES IN SCHEMA ",schem," GRANT ALL ON SEQUENCES TO runner;")) + expect_snapshot(list_tables(schema = schem, db = "test_datalibaba", user = "test")) + con<<-connect_to_db(db = 'test_datalibaba', user = 'test') + expect_snapshot(list_tables(schema = schem, con = con)) + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("poster_data works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + #tests poster_data + + expect_error(poster_data(table = "test_iris", schema = "public", db = "test_datalibaba", + pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"), + "'data' n\'est pas renseign\u00e9") + expect_error(poster_data(data=c(1,2,3), table = "test_iris", schema = "public", db = "test_datalibaba", + pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"), + "le dataframe 'data' n\'exsiste pas") + expect_error(poster_data(data = iris, table = "test_iris", schema = "public", db = "test_datalibaba", + pk = "Speciez", post_row_name = FALSE, overwrite = TRUE, user = "test"), + "mauvaise declaration de pk : doit etre 1 ou NULL ou un nom de variable de 'data' ou un vecteur de noms de variables de 'data'") + expect_error(poster_data(data = iris, table = "test_iris", db = "test_datalibaba", + pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"), + "schema n\'est pas renseign\u00e9") + expect_error(poster_data(data = iris, schema = "public", db = "test_datalibaba", + pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"), + "table n\'est pas renseign\u00e9") + + # test création schema, post_row_name, ecoSQL, pk et overwrite + + schem <- paste0("test_",sample.int(1000, 1),"_",sample.int(1000, 1)) + + expect_warning(poster_data(data = iris, table = "test_iris", schema = schem, db = "test_datalibaba", pk = NULL, post_row_name = TRUE, overwrite = TRUE, user = "test"), + paste0("le schema ",schem," n\\'existe pas\\. Il va être créé sous test_datalibaba\\.")) + + df<-iris %>% rownames_to_column("id") %>% mutate(todate = parse_date_time("2025-02-27 14:29:32", "Ymd HMS")) + + expect_message(poster_data(data = df, table = "test_iris", schema = "public", db = "test_datalibaba", pk = "id", post_row_name = TRUE, overwrite = TRUE, user = "test", ecoSQL = FALSE), + "\u00e9crit dans la table ") + expect_message(poster_data(data = df, table = "test_iris", schema = "public", db = "test_datalibaba", pk = 1, post_row_name = TRUE, overwrite = TRUE, user = "test"), + "\u00e9crit dans la table ") + expect_error(poster_data(data = iris, table = "test_iris", schema = schem, db = "test_datalibaba", pk = NULL, post_row_name = FALSE, overwrite = FALSE, user = "test"), + paste0("La table test_iris existe d\u00e9j\u00e0 sur le schema ",schem," et le param\u00e8tre overwrite est \u00e0 FALSE")) + + # test geometry + nc <- st_read(system.file("shape/nc.shp", package="sf")) + expect_message(poster_data(data = nc, table = "nc", schema = "public", db = "test_datalibaba", pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"), + "\u00e9crit dans la table ") + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("post_data works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + expect_error(post_data(con=NULL, data = iris, schema = "public", table = "test_iris", overwrite = FALSE), + "con n\'est pas renseign\u00e9") + expect_error(post_data(con=connect_to_db(db = 'test_datalibaba', user = 'test'), data = iris, schema = "public", table = "test_iris", overwrite = FALSE), + "le connecteur con n\'existe pas dans l\'environnement") + con<<-connect_to_db(db = 'test_datalibaba', user = 'test') + expect_error(post_data(con=con, data = iris, schema = "public", table = "test_iris", overwrite = FALSE), + "veuillez utiliser une connexion avec ecoSQL=FALSE") + con<<-connect_to_db(db = 'test_datalibaba', user = 'test', ecoSQL = FALSE) + expect_error(post_data(con=con, schema = "public", table = "test_iris", overwrite = FALSE), + "data n\'est pas renseign\u00e9") + expect_error(post_data(con=con, data=c(1), schema = "public", table = "test_iris", overwrite = FALSE), + glue::glue("le dataframe 1 n\'exsiste pas")) + expect_error(post_data(con=con, data = iris, table = "test_iris", overwrite = FALSE), + "schema n\'est pas renseign\u00e9") + expect_error(post_data(con=con, data = iris, schema = "public", overwrite = FALSE), + "table n\'est pas renseign\u00e9") + expect_error(post_data(con=con, data = iris, schema = "titi-test", table = "test_iris", overwrite = FALSE), + glue::glue("le schema titi-test n\'existe pas")) + + post_data(con, data = iris, schema = "public", table = "retest_iris", overwrite = TRUE) + + expect_error(post_data(con, data = iris, schema = "public", table = "retest_iris", overwrite = FALSE), + paste0("La table retest_iris existe d\u00e9j\u00e0 sur le schema public et le param\u00e8 tre overwrite est \u00e0 FALSE")) + expect_message(post_data(con, data = iris, schema = "public", table = "retest_iris", overwrite = TRUE), + " est \u00e9cras\u00e9e sur le schema ") + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("post_data_dbi works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + con<<-connect_to_db(db = 'test_datalibaba', user = 'test', ecoSQL = FALSE) + expect_message(suppressWarnings(post_data_dbi(con, data = iris, schema = "public", table = "retest_iris", overwrite = TRUE)), + " est \u00e9cras\u00e9e sur le schema ") + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) diff --git a/tests/testthat/test-5-get_data.R b/tests/testthat/test-5-get_data.R new file mode 100644 index 0000000000000000000000000000000000000000..3b1f1383d2e046e68dd4d59d2ea487d647bcf3bc --- /dev/null +++ b/tests/testthat/test-5-get_data.R @@ -0,0 +1,125 @@ +library(DBI) +library(magrittr) +library(tibble) +library(lubridate) +library(dplyr) +library(sf) +library(glue) +library(backports) +library(withr) + +test_that("importer_data no geo works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + expect_error(importer_data(schema = "public", db = "test_datalibaba", user = "test"), + "l'argument table n'est pas renseign\u00e9") + expect_error(importer_data(table = "test_iris", db = "test_datalibaba", user = "test"), + "l'argument schema n'est pas renseign\u00e9") + expect_error(importer_data(table = "test_iris", schema = "public", db = NULL, user = "test"), + "l'argument db n'est pas renseign\u00e9") + expect_error(importer_data(table = "test_iris", schema = "public", db = "test_datalibaba", user = NULL), + "l'argument user n'est pas renseign\u00e9") + expect_error(importer_data(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test", limit="d"), + "l'argument limit n'est pas num\u00e9rique") + + expect_error(importer_data(table = "titi-test", schema = "public", db = "test_datalibaba", user = "test"), + paste0("La table 'public'.'titi-test' est introuvable.")) + # test avec création schema sans table de propriétés + schem <- paste0("test_",sample.int(1000, 1),"_",sample.int(1000, 1)) + suppressWarnings(poster_data(data = iris, table = "test_iris", schema = schem, db = "test_datalibaba", pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test")) + condirect <- DBI::dbConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="test_datalibaba") + DBI::dbExecute(condirect, paste0("DELETE FROM ",schem,".zz_r_df_def;")) + expect_message(importer_data(table = "test_iris", schema = schem, db = "test_datalibaba", user = "test"), + paste0("Pas de renseignements trouv\u00e9 sur test_iris dans la table des propri\u00e9t\u00e9s des dataframes R, un import standard sera r\u00e9alis\u00e9. ")) + + DBI::dbExecute(condirect, paste0("DROP TABLE IF EXISTS ",schem,".zz_r_df_def CASCADE;")) + expect_message(importer_data(table = "test_iris", schema = schem, db = "test_datalibaba", user = "test"), + "La table de propri\u00e9t\u00e9s des dataframes R est introuvable, un import standard sera r\u00e9alis\u00e9. ") + # test basic + expect_snapshot(importer_data(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test", limit = 4, ecoSQL = FALSE)) + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("importer_data geo works", { + withr::local_options(lifecycle_verbosity = "quiet") + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + # test geometry # pas pris en compte dans le coverage... pourquoi ?? + expect_snapshot(importer_data(table = "nc", schema = "public", db = "test_datalibaba", user = "test")) + expect_snapshot(importer_data(table = "nc", schema = "public", db = "test_datalibaba", user = "test", limit = 4)) + nc <- st_read(system.file("shape/nc.shp", package="sf")) + poster_data(data = nc, table = "test_nc_noid", schema = "public", db = "test_datalibaba", pk = "CNTY_ID", post_row_name = FALSE, overwrite = TRUE, user = "test") + expect_snapshot(importer_data(table = "test_nc_noid", schema = "public", db = "test_datalibaba", user = "test", limit = 4)) + #A FINIR !!! + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("get_data works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + expect_error(get_data(con=NULL, schema = "public", table = "test_iris"), + "con n\'est pas renseign\u00e9") + con<<-connect_to_db(db = 'test_datalibaba', user = 'test') + expect_error(get_data(con=con, schema = "public", table = "test_iris"), + "veuillez utiliser une connexion avec ecoSQL=FALSE") + con<<-connect_to_db(db = 'test_datalibaba', user = 'test', ecoSQL = FALSE) + expect_error(get_data(con=con, table = "test_iris"), + "schema n\'est pas renseign\u00e9") + expect_error(get_data(con=con, schema = "public"), + "table n\'est pas renseign\u00e9") + expect_snapshot(get_data(con=con, schema = "public", table = "test_iris")) + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("get_data_dbi works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + expect_error(get_data_dbi(con=NULL, schema = "public", table = "test_iris"), + "con n\'est pas renseign\u00e9") + con<<-connect_to_db(db = 'test_datalibaba', user = 'test', ecoSQL = FALSE) + expect_error(get_data_dbi(con=con, schema = "public", table = "test_iris"), + "veuillez utiliser une connexion avec ecoSQL=TRUE") + con<<-connect_to_db(db = 'test_datalibaba', user = 'test') + expect_error(get_data_dbi(con=con, table = "test_iris"), + "schema n\'est pas renseign\u00e9") + expect_error(get_data_dbi(con=con, schema = "public"), + "table n\'est pas renseign\u00e9") + expect_snapshot(get_data_dbi(con=con, schema = "public", table = "test_iris")) + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) diff --git a/tests/testthat/test-6-comment_db.R b/tests/testthat/test-6-comment_db.R new file mode 100644 index 0000000000000000000000000000000000000000..52bbe26ae04a2252f4a14b48d864363b45d1297f --- /dev/null +++ b/tests/testthat/test-6-comment_db.R @@ -0,0 +1,49 @@ +test_that("get_db_comment works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + expect_snapshot(get_db_comment(db = "test_datalibaba", user = "test", server = Sys.getenv("server"))) + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("commenter_schema works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + expect_error(commenter_schema(schema = "public", db = "test_datalibaba", user = "test"), + "L'argument comment n\'est pas renseign\u00e9. ") + expect_error(commenter_schema(comment = "un petit schema !", db = "test_datalibaba", user = "test"), + "L\'argument schema n\'est pas renseign\u00e9. ") + expect_null(commenter_schema(comment = "le schema des tests qui restent !", schema = "public", db = "test_datalibaba", user = "test")) + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("get_schema_comment works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + expect_error(get_schema_comment(db = "test_datalibaba", user = "test", server = Sys.getenv("server")), + "L\'argument schema n\'est pas renseign\u00e9. ") + expect_error(get_schema_comment(schema="titi-test", db = "test_datalibaba", user = "test", server = Sys.getenv("server")), + "Il n\'y a pas de schema titi-test dans la base de donn\u00e9es. ") + expect_snapshot(get_schema_comment(schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server"))) + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) diff --git a/tests/testthat/test-7-commenter_champs.R b/tests/testthat/test-7-commenter_champs.R new file mode 100644 index 0000000000000000000000000000000000000000..ca403284473d94aae9fb6e93007029e84556bc68 --- /dev/null +++ b/tests/testthat/test-7-commenter_champs.R @@ -0,0 +1,175 @@ +library(DBI) +library(magrittr) +library(tibble) +library(lubridate) +library(dplyr) +library(glue) + +test_that("commenter_champs works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + expect_error(commenter_champs(var = "Species", table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"), + "L\'argument comment n\'est pas renseign\u00e9. ") + expect_error(commenter_champs(comment = "Commentlibaba !", table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"), + "L\'argument var n\'est pas renseign\u00e9. ") + expect_error(commenter_champs(comment = "Commentlibaba !", var = "Species", table = "test_iris", db = "test_datalibaba", user = "test"), + "L\'argument schema n\'est pas renseign\u00e9. ") + expect_error(commenter_champs(comment = "Commentlibaba !", var = "Species", schema = "public", db = "test_datalibaba", user = "test"), + "L\'argument table n\'est pas renseign\u00e9. ") + expect_error(commenter_champs(comment = "Commentlibaba !", var = "Species", table = "test_titi", schema = "public", db = "test_datalibaba", user = "test"), + "Il n\'y a pas de table test_titi dans le schema public. ") + expect_error(commenter_champs(comment = "Commentlibaba !", var = "titi", table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"), + "Il n\'y a pas de champ titi dans la table test_iris. ") + + expect_null(commenter_champs(comment = "Commentlibaba !", var = "Species", table = "test_iris", schema = "public", db = "test_datalibaba", user = "test")) + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("post_dico_attr works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + dico_iris <- data.frame(VAR = names(iris), VAR_LIB = paste("libell\u00e9 de", names(iris), " cc")) + expect_error(post_dico_attr(dico = c(1), table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"), + "L\'argument dico ne correpond pas \u00e0 un dataframe. ") + expect_error(post_dico_attr(dico = data.frame(), table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"), + "L\'argument dico est vide. ") + expect_error(post_dico_attr(dico = dico_iris %>% mutate(otr="detrop"), table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"), + "L\'argument dico doit comprendre 2 champs : le 1er pour le nom des variables, le second pour leur explicitation. ") + expect_error(post_dico_attr(dico = dico_iris, table = "test_iris", db = "test_datalibaba", user = "test"), + "L\'argument schema n\'est pas renseign\u00e9. ") + expect_error(post_dico_attr(dico = dico_iris, schema = "public", db = "test_datalibaba", user = "test"), + "L\'argument table n\'est pas renseign\u00e9. ") + expect_error(post_dico_attr(dico = dico_iris, table = "titi_test", schema = "public", db = "test_datalibaba", user = "test"), + "Il n\'y a pas de table titi_test dans le schema public. ") + expect_error(post_dico_attr(dico = dico_iris, table = "nc", schema = "public", db = "test_datalibaba", user = "test"), + "Les champs list\u00e9s dans 'dico' ne se retrouvent pas tous dans la table nc. ") + + expect_null(post_dico_attr(dico = dico_iris, table = "retest_iris", schema = "public", db = "test_datalibaba", user = "test")) + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("get_cols_comment works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + expect_error(get_cols_comment(table = "test_iris", db = "test_datalibaba", user = "test", server = Sys.getenv("server")), + "L\'argument schema n\'est pas renseign\u00e9. ") + expect_error(get_cols_comment(schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")), + "L\'argument table n\'est pas renseign\u00e9. ") + expect_error(get_cols_comment(table = "titi_test", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")), + "Il n\'y a pas de table titi_test dans le schema public. ") + + expect_snapshot(get_cols_comment(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server"))) + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("get_table_comments works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + expect_snapshot(get_table_comments(table = "retest_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server"))) + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("get_table_comment works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + expect_error(get_table_comment(table = "test_iris", db = "test_datalibaba", user = "test", server = Sys.getenv("server")), + "L\'argument schema n\'est pas renseign\u00e9. ") + expect_error(get_table_comment(schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")), + "L\'argument table n\'est pas renseign\u00e9. ") + expect_error(get_table_comment(table = "titi_test", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")), + "Il n\'y a pas de table titi_test dans le schema public. ") + + expect_snapshot(get_table_comment(table = "retest_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server"))) + + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("transferer_table_comments works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + expect_null(transferer_table_comments(table_sce = "retest_iris", schema_sce = "public", db_sce = "test_datalibaba", table_dest = "test_iris", schema_dest = "public", db_dest = "test_datalibaba", user = "test", server = Sys.getenv("server"))) + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) + +test_that("exporter_table_comments works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + mon_dossier_temp_aleatoire <- tempfile(pattern = "test_exporter_table_comments") + dir.create(mon_dossier_temp_aleatoire) + fichier_temp <- file.path(mon_dossier_temp_aleatoire, "comment_iris.csv") + + expect_message(exporter_table_comments(table = "retest_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server"), fichier = fichier_temp, import = TRUE), + "Export du dictionnaire des variables csv") + + # On vérifie que le fichier a bien été écrit en sortie + expect_true(file.exists(fichier_temp)) + # On vérifie que la taille du fichier est non nulle + expect_true(file.info(fichier_temp)$size > 0) + + unlink(mon_dossier_temp_aleatoire, recursive = TRUE) + + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) diff --git a/tests/testthat/test-8-commenter_table.R b/tests/testthat/test-8-commenter_table.R new file mode 100644 index 0000000000000000000000000000000000000000..8f265cf3d9cc071d87145ff9e3f2df886cd3bd7a --- /dev/null +++ b/tests/testthat/test-8-commenter_table.R @@ -0,0 +1,22 @@ +test_that("commenter_table works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + expect_error(commenter_table(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"), + "L'argument comment n\'est pas renseign\u00e9. ") + expect_error(commenter_table(comment = "la table de test complete", table = "test_iris", db = "test_datalibaba", user = "test"), + "L\'argument schema n\'est pas renseign\u00e9. ") + expect_error(commenter_table(comment = "la table de test complete", schema = "public", db = "test_datalibaba", user = "test"), + "L\'argument table n\'est pas renseign\u00e9. ") + expect_error(commenter_table(comment = "la table de test complete", table = "titi_test", schema = "public", db = "test_datalibaba", user = "test"), + "Il n\'y a pas de table titi_test dans le schema public. ") + expect_message(commenter_table(comment = "la table de test complete", table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"), + "COMMENT ON TABLE \"public\".\"test_iris\" IS 'la table de test complete") + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +}) diff --git a/tests/testthat/test-9-set_schema_rights.R b/tests/testthat/test-9-set_schema_rights.R new file mode 100644 index 0000000000000000000000000000000000000000..e56f7762ced1b71c897c8dcc57fddb9e053beaab --- /dev/null +++ b/tests/testthat/test-9-set_schema_rights.R @@ -0,0 +1,26 @@ +test_that("set_schema_rights works", { + if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ + Sys.setenv(port="5432") + Sys.setenv(server="localhost") + Sys.setenv(user_test="runner") + Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) + + con<<-connect_to_db(db = 'test_datalibaba', user = 'test') + + expect_error(set_schema_rights(schema = "public", table = "test_iris", db = NULL, user = NULL, server = Sys.getenv("server")), + "con, db et user ne sont pas renseign\u00e9s, merci de fournir les arguments necessaires a la connexion ") + expect_error(set_schema_rights(schema = "public", table = "test_iris", db = NULL, user = "test", server = Sys.getenv("server")), + "con et db ne sont pas renseign\u00e9s, merci de fournir les arguments necessaires a la connexion ") + expect_error(set_schema_rights(schema = "public", table = "test_iris", db = "test_datalibaba", user = NULL, server = Sys.getenv("server")), + "con et user ne sont pas renseign\u00e9s, merci de fournir les arguments necessaires a la connexion ") + expect_error(set_schema_rights(schema = NULL, table = "test_iris", con = con, db = "test_datalibaba", user = "test", server = Sys.getenv("server")), + "schema n'est pas renseign\u00e9. ") + + expect_null(set_schema_rights(schema = "public", table = "test_iris", db = "test_datalibaba", user = "test", server = Sys.getenv("server"))) + + }else{ + print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) + print('warning: connect_to_db - local database postgresql doesnt work !') + expect_equal(1,1) + } +})