Fixed lintr & complexity issues
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return(tbl)
|
tbl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ insertRows <- function(table_name, rows, key_name = NULL) {
|
|||||||
return(dbplyr::get_returned_rows(tbl))
|
return(dbplyr::get_returned_rows(tbl))
|
||||||
}
|
}
|
||||||
|
|
||||||
return(invisible(tbl))
|
invisible(tbl)
|
||||||
}
|
}
|
||||||
|
|
||||||
appendRows <- function(table_name, rows, key_name = NULL) {
|
appendRows <- function(table_name, rows, key_name = NULL) {
|
||||||
@@ -64,7 +64,7 @@ appendRows <- function(table_name, rows, key_name = NULL) {
|
|||||||
return(dbplyr::get_returned_rows(tbl))
|
return(dbplyr::get_returned_rows(tbl))
|
||||||
}
|
}
|
||||||
|
|
||||||
return(invisible(TRUE))
|
invisible(TRUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
upsertRows <- function(table_name, rows, key_name = NULL) {
|
upsertRows <- function(table_name, rows, key_name = NULL) {
|
||||||
@@ -98,7 +98,7 @@ upsertRows <- function(table_name, rows, key_name = NULL) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(invisible(TRUE))
|
invisible(TRUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRows <- function(table_name, rows, key_name = NULL) {
|
updateRows <- function(table_name, rows, key_name = NULL) {
|
||||||
@@ -122,7 +122,7 @@ updateRows <- function(table_name, rows, key_name = NULL) {
|
|||||||
return(dbplyr::get_returned_rows(tbl))
|
return(dbplyr::get_returned_rows(tbl))
|
||||||
}
|
}
|
||||||
|
|
||||||
return(invisible(TRUE))
|
invisible(TRUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteRows <- function(table_name, rows, key_name = NULL) {
|
deleteRows <- function(table_name, rows, key_name = NULL) {
|
||||||
@@ -151,5 +151,5 @@ deleteRows <- function(table_name, rows, key_name = NULL) {
|
|||||||
return(dbplyr::get_returned_rows(tbl))
|
return(dbplyr::get_returned_rows(tbl))
|
||||||
}
|
}
|
||||||
|
|
||||||
return(invisible(TRUE))
|
invisible(TRUE)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ conn <- NULL
|
|||||||
NULL
|
NULL
|
||||||
initialize <- function(conn) {
|
initialize <- function(conn) {
|
||||||
if (is.null(conn) || !R6::is.R6(conn) || !inherits(conn, "DBConnection")) {
|
if (is.null(conn) || !R6::is.R6(conn) || !inherits(conn, "DBConnection")) {
|
||||||
stop("DBConnection instance required!")
|
stop("DBConnection instance required!")
|
||||||
}
|
}
|
||||||
private$conn <- conn
|
private$conn <- conn
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,34 +50,34 @@ collectGeometries <- function(
|
|||||||
|
|
||||||
if (sum(geometry_cols %in% colnames(res)) > 0) {
|
if (sum(geometry_cols %in% colnames(res)) > 0) {
|
||||||
res <- dplyr::mutate(
|
res <- dplyr::mutate(
|
||||||
res,
|
res,
|
||||||
dplyr::across(dplyr::any_of(geometry_cols), function(.col) {
|
dplyr::across(dplyr::any_of(geometry_cols), function(.col) {
|
||||||
sf::st_as_sfc(
|
sf::st_as_sfc(
|
||||||
.col,
|
.col,
|
||||||
EWKB = TRUE,
|
EWKB = TRUE,
|
||||||
crs = geometry_crs,
|
crs = geometry_crs,
|
||||||
check_ring_dir = check_ring_dir
|
check_ring_dir = check_ring_dir
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("geom" %in% colnames(res) && sum("geom" %in% geometry_cols) == 0) {
|
if ("geom" %in% colnames(res) && sum("geom" %in% geometry_cols) == 0) {
|
||||||
res <- dplyr::mutate(
|
res <- dplyr::mutate(
|
||||||
res,
|
res,
|
||||||
geom = sf::st_as_sfc(
|
geom = sf::st_as_sfc(
|
||||||
.data$geom, EWKB = TRUE, crs = 4326, check_ring_dir = check_ring_dir
|
.data$geom, EWKB = TRUE, crs = 4326, check_ring_dir = check_ring_dir
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("proj" %in% colnames(res) && sum("proj" %in% geometry_cols) == 0) {
|
if ("proj" %in% colnames(res) && sum("proj" %in% geometry_cols) == 0) {
|
||||||
res <- dplyr::mutate(
|
res <- dplyr::mutate(
|
||||||
res,
|
res,
|
||||||
proj = sf::st_as_sfc(
|
proj = sf::st_as_sfc(
|
||||||
.data$proj, EWKB = TRUE, crs = 3035, check_ring_dir = check_ring_dir
|
.data$proj, EWKB = TRUE, crs = 3035, check_ring_dir = check_ring_dir
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ NULL
|
|||||||
withSchema <- function(table_name) {
|
withSchema <- function(table_name) {
|
||||||
config <- private$conn$getConfiguration()
|
config <- private$conn$getConfiguration()
|
||||||
if (exists("schema", config)) {
|
if (exists("schema", config)) {
|
||||||
return(DBI::dbQuoteIdentifier(
|
DBI::dbQuoteIdentifier(
|
||||||
private$getDBConn(), DBI::Id(schema = config$schema, table = table_name)
|
private$getDBConn(), DBI::Id(schema = config$schema, table = table_name)
|
||||||
))
|
)
|
||||||
} else {
|
} else {
|
||||||
return(DBI::dbQuoteIdentifier(
|
DBI::dbQuoteIdentifier(
|
||||||
private$getDBConn(), DBI::Id(table = table_name)
|
private$getDBConn(), DBI::Id(table = table_name)
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,8 +32,8 @@ NULL
|
|||||||
dplyrWithSchema <- function(table_name) {
|
dplyrWithSchema <- function(table_name) {
|
||||||
config <- private$conn$getConfiguration()
|
config <- private$conn$getConfiguration()
|
||||||
if (exists("schema", config) && !is.null(config$schema)) {
|
if (exists("schema", config) && !is.null(config$schema)) {
|
||||||
return(dbplyr::in_schema(config$schema, table_name))
|
dbplyr::in_schema(config$schema, table_name)
|
||||||
} else {
|
} else {
|
||||||
return(table_name)
|
table_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ names(member_list) <- member_names
|
|||||||
NULL
|
NULL
|
||||||
|
|
||||||
#' @export
|
#' @export
|
||||||
|
# nolint next: object_name_linter. R6Class
|
||||||
DBClient <- R6::R6Class(
|
DBClient <- R6::R6Class(
|
||||||
"DBClient",
|
"DBClient",
|
||||||
public = fn_list,
|
public = fn_list,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ connect <- function() {
|
|||||||
error = function(err) {
|
error = function(err) {
|
||||||
print("Database error:")
|
print("Database error:")
|
||||||
utils::str(err)
|
utils::str(err)
|
||||||
return(FALSE)
|
FALSE
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ NULL
|
|||||||
getConnection <- function(do_connect = NULL) {
|
getConnection <- function(do_connect = NULL) {
|
||||||
if (!self$isConnected()) {
|
if (!self$isConnected()) {
|
||||||
if ((!is.null(do_connect) && do_connect)
|
if ((!is.null(do_connect) && do_connect)
|
||||||
|| (is.null(do_connect) && private$conn$autoconnect)) {
|
|| (is.null(do_connect) && private$conn$autoconnect)) {
|
||||||
connect()
|
connect()
|
||||||
} else {
|
} else {
|
||||||
warning("Database is not connected. Caller of getConnection() may error.")
|
warning("Database is not connected. Caller of getConnection() may error.")
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ transactionLevel <- 0
|
|||||||
NULL
|
NULL
|
||||||
beginTransaction <- function(allowRecursive = FALSE, quietly = FALSE) {
|
beginTransaction <- function(allowRecursive = FALSE, quietly = FALSE) {
|
||||||
if (private$transactionLevel > 0) {
|
if (private$transactionLevel > 0) {
|
||||||
if (allowRecursive == FALSE) {
|
if (allowRecursive == FALSE) {
|
||||||
if (quietly != FALSE) {
|
if (quietly != FALSE) {
|
||||||
stop("Transaction already started. Aborting.")
|
stop("Transaction already started. Aborting.")
|
||||||
}
|
}
|
||||||
return(FALSE)
|
return(FALSE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private$transactionLevel <- private$transactionLevel + 1
|
private$transactionLevel <- private$transactionLevel + 1
|
||||||
DBI::dbBegin(self$getConnection())
|
DBI::dbBegin(self$getConnection())
|
||||||
@@ -63,7 +63,7 @@ commitTransaction <- function(quietly = FALSE) {
|
|||||||
}
|
}
|
||||||
private$transactionLevel <- private$transactionLevel - 1
|
private$transactionLevel <- private$transactionLevel - 1
|
||||||
if (transactionLevel > 0) {
|
if (transactionLevel > 0) {
|
||||||
return(TRUE)
|
return(TRUE)
|
||||||
}
|
}
|
||||||
DBI::dbRollback(self$getConnection())
|
DBI::dbRollback(self$getConnection())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ names(member_list) <- member_names
|
|||||||
NULL
|
NULL
|
||||||
|
|
||||||
#' @export
|
#' @export
|
||||||
|
# nolint next: object_name_linter. R6Class
|
||||||
DBConnection <- R6::R6Class(
|
DBConnection <- R6::R6Class(
|
||||||
"DBConnection",
|
"DBConnection",
|
||||||
public = fn_list,
|
public = fn_list,
|
||||||
|
|||||||
4
R/aaa.R
4
R/aaa.R
@@ -1,5 +1,5 @@
|
|||||||
if(getRversion() >= "2.15.1") utils::globalVariables(c("self"))
|
if (getRversion() >= "2.15.1") utils::globalVariables(c("self"))
|
||||||
if(getRversion() >= "2.15.1") utils::globalVariables(c("private"))
|
if (getRversion() >= "2.15.1") utils::globalVariables(c("private"))
|
||||||
|
|
||||||
#' @importFrom rlang :=
|
#' @importFrom rlang :=
|
||||||
#' @importFrom rlang .data
|
#' @importFrom rlang .data
|
||||||
|
|||||||
Reference in New Issue
Block a user