Kaynağa Gözat

Töötav versioon kuni bbox salvestamiseni.

Ardo Kubjas 5 yıl önce
ebeveyn
işleme
e660f96c80

+ 2 - 3
R/copy_polygon_to_db.R

@@ -29,9 +29,8 @@ copy_polygon_to_db <- function(x = NULL, conf = NULL, id = "fid",
       conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode,
       conf$schema, x, id, conf$schema, conf$table, crs_source, crs_target
     )
-    source(paste0(getwd(), "/R/db_create_new_schema.R"))
-    # Create new schema if not exist.
-    db_create_new_schema(conf)
+    ruut::db_create_new_schema(conf)
+    Sys.sleep(2)
     system(cmd)
   } else {
     NULL

+ 8 - 4
R/db_all_schemas.R

@@ -1,8 +1,12 @@
-# Andmebaasi kõikide schema'de nimekiri.
+#' List of all database schemas
+#'
+#' Valitud andmebaasi kõikide schemade nimekiri.
+#' @keywords database, schema
+#' @export
+#' @examples
+#' db_all_schemas()
 db_all_schemas <- function() {
-  source(paste0(getwd(), "/R/db_connect.R"))
-  conn <- db_connect()
+  conn <- ruut::db_connect()
   all_schemas <- DBI::dbGetQuery(conn, "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA")
   return(all_schemas$schema_name)
 }
-# db_all_schemas()

+ 9 - 0
R/db_connect.R

@@ -1,3 +1,12 @@
+#' Connect to database
+#'
+#' Andmebaasiga ühenduse looomine.
+#' @param conf	list List of configuration data. Rewrite it.
+#' @keywords database, schema
+#' @export
+#' @examples
+#' config <- get_config()
+#' conn <- db_connect(conf = config)
 db_connect <- function(conf = NULL) {
   if (is.null(conf)) {
     config <- ruut::get_config()

+ 11 - 4
R/db_create_new_schema.R

@@ -1,8 +1,15 @@
-# Loome uue schema
+#' Create the new schema
+#'
+#' Loome andmebaasi uue schema.
+#' @param conf	list List of configuration data. Rewrite it.
+#' @keywords database, schema
+#' @export
+#' @examples
+#' config <- get_config()
+#' db_create_new_schema(conf = config)
 db_create_new_schema <- function(conf) {
-  source(paste0(getwd(), "/R/db_is_shema_exist.R"))
-  if (!db_is_shema_exist(conf$schema)) {
-    conn <- db_connect()
+  if (!ruut::db_is_shema_exist(conf$schema)) {
+    conn <- ruut::db_connect()
     DBI::dbExecute(conn, sprintf(
       "-- DROP SCHEMA x_matsalu;
 CREATE SCHEMA %s AUTHORIZATION %s;", conf$schema, conf$user

+ 9 - 4
R/db_is_shema_exist.R

@@ -1,10 +1,15 @@
-# Kas schema eksisteerib.
+#' Does the schema exist
+#'
+#' Kontrollime kas andmebaasis antud schema eksisteerib.
+#' @param schema	str Database schema name.
+#' @keywords database, schema
+#' @export
+#' @examples
+#' db_is_shema_exist(schema = "public")
 db_is_shema_exist <- function(schema = NULL) {
-  source(paste0(getwd(), "/R/db_all_schemas.R"))
-  if (schema %in% db_all_schemas()) {
+  if (schema %in% ruut::db_all_schemas()) {
     TRUE
   } else {
     FALSE
   }
 }
-# db_is_shema_exist(schema = "x_matsalu")

+ 4 - 2
R/get_config.R

@@ -1,14 +1,16 @@
 #' Mooduli konfiguratsioon andmed
 #'
-#' JSONi konfiguratsioon faili lugemine. Muuda seda faili vajadusel. Rakenda seda funktsiooni oma konfiguratsioonifailile.
+#' JSONi konfiguratsioon faili lugemine. Muuda seda faili vajadusel. Rakenda seda funktsiooni oma konfiguratsioonifailile. Asendame defaul schema nime "date_YYMMDD" tegeliku tänase kuupäevaga, et ei kirjutaks andmebaasis juhuslikult midagi üle. Oma scema lisamiseks config$schema <- "oma_schema".
 #' @param conf json fail konfiguratsioon muutujate argumentidega.
 #' @keywords cats
 #' @export
 #' @examples
-#' get_config()
+#' config <- get_config()
+#' config
 get_config <- function(conf = NULL) {
   if (is.null(conf)) {
     config <- rjson::fromJSON(file = system.file("extdata", "config.json", package = "ruut"))
+    config$schema <- sprintf("date_%s", format(Sys.Date(), "%y%m%d"))
   }
   else {
     config <- conf

+ 4 - 4
man/copy_polygon_to_db.Rd

@@ -7,7 +7,7 @@
 copy_polygon_to_db(
   x = NULL,
   conf = NULL,
-  id = "id",
+  id = "fid",
   crs_source = "EPSG:4326",
   crs_target = "EPSG:4326"
 )
@@ -15,11 +15,11 @@ copy_polygon_to_db(
 \arguments{
 \item{x}{object of "qgis_result" spatial polygon.}
 
-\item{conf}{list database configuration.}
+\item{conf}{list database configuration. Default get_config()}
 
-\item{id}{field andmebaasi unikaalne id veerg.}
+\item{id}{field andmebaasi unikaalne id veerg. Default 'fid'}
 
-\item{crs_source}{CRS source CRS for example 'EPSG:3301' (estonia). Default is 'EPSG:4326'.}
+\item{crs_source}{CRS source CRS for example 'EPSG:3301' (Estonia). Default is 'EPSG:4326'.}
 
 \item{crs_target}{CRS target CRS for example 'EPSG:4326'. Default is 'EPSG:4326'.}
 }

+ 16 - 0
man/db_all_schemas.Rd

@@ -0,0 +1,16 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/db_all_schemas.R
+\name{db_all_schemas}
+\alias{db_all_schemas}
+\title{List of all database schemas}
+\usage{
+db_all_schemas()
+}
+\description{
+Valitud andmebaasi kõikide schemade nimekiri.
+}
+\examples{
+db_all_schemas()
+}
+\keyword{database,}
+\keyword{schema}

+ 20 - 0
man/db_connect.Rd

@@ -0,0 +1,20 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/db_connect.R
+\name{db_connect}
+\alias{db_connect}
+\title{Connect to database}
+\usage{
+db_connect(conf = NULL)
+}
+\arguments{
+\item{conf}{list List of configuration data. Rewrite it.}
+}
+\description{
+Andmebaasiga ühenduse looomine.
+}
+\examples{
+config <- get_config()
+conn <- db_connect(conf = config)
+}
+\keyword{database,}
+\keyword{schema}

+ 20 - 0
man/db_create_new_schema.Rd

@@ -0,0 +1,20 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/db_create_new_schema.R
+\name{db_create_new_schema}
+\alias{db_create_new_schema}
+\title{Create the new schema}
+\usage{
+db_create_new_schema(conf)
+}
+\arguments{
+\item{conf}{list List of configuration data. Rewrite it.}
+}
+\description{
+Loome andmebaasi uue schema.
+}
+\examples{
+config <- get_config()
+db_create_new_schema(conf = config)
+}
+\keyword{database,}
+\keyword{schema}

+ 19 - 0
man/db_is_shema_exist.Rd

@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/db_is_shema_exist.R
+\name{db_is_shema_exist}
+\alias{db_is_shema_exist}
+\title{Does the schema exist}
+\usage{
+db_is_shema_exist(schema = NULL)
+}
+\arguments{
+\item{schema}{str Database schema name.}
+}
+\description{
+Kontrollime kas andmebaasis antud schema eksisteerib.
+}
+\examples{
+db_is_shema_exist(schema = "public")
+}
+\keyword{database,}
+\keyword{schema}

+ 3 - 2
man/get_config.Rd

@@ -10,9 +10,10 @@ get_config(conf = NULL)
 \item{conf}{json fail konfiguratsioon muutujate argumentidega.}
 }
 \description{
-JSONi konfiguratsioon faili lugemine. Muuda seda faili vajadusel. Rakenda seda funktsiooni oma konfiguratsioonifailile.
+JSONi konfiguratsioon faili lugemine. Muuda seda faili vajadusel. Rakenda seda funktsiooni oma konfiguratsioonifailile. Asendame defaul schema nime "date_YYMMDD" tegeliku tänase kuupäevaga, et ei kirjutaks andmebaasis juhuslikult midagi üle. Oma scema lisamiseks config$schema <- "oma_schema".
 }
 \examples{
-get_config()
+config <- get_config()
+config
 }
 \keyword{cats}