From 1ee9209e934cf316d77919fd9ba4022367440b49 Mon Sep 17 00:00:00 2001 From: Susana Quartin Date: Mon, 13 Aug 2018 12:23:48 +0100 Subject: [PATCH] Reorganinze package structure Have one file per exported function --- R/as_sql_array.R | 10 ++++++++++ R/db_table.R | 15 +++++++++++++++ R/{dbutils.R => fetch_db.R} | 27 --------------------------- man/as_sql_array.Rd | 5 ++++- man/db_table.Rd | 5 ++++- 5 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 R/as_sql_array.R create mode 100644 R/db_table.R rename R/{dbutils.R => fetch_db.R} (50%) diff --git a/R/as_sql_array.R b/R/as_sql_array.R new file mode 100644 index 0000000..de6cbe2 --- /dev/null +++ b/R/as_sql_array.R @@ -0,0 +1,10 @@ +#' @export +#' @title Transform a vector into a SQL-interpreted array. +#' +#' @param vector character vector +#' @return +#' List with a single string that's interpreted as a SQL array to interpolate in a query. +as_sql_array <- function(vector) { + array <- paste0("(", paste(paste0("'", vector, "'"), collapse = ", "), ")") + list(array) +} diff --git a/R/db_table.R b/R/db_table.R new file mode 100644 index 0000000..7b047c1 --- /dev/null +++ b/R/db_table.R @@ -0,0 +1,15 @@ +#' @export +#' @title Create a tbl that references a schema.table in the `conn` database. +#' +#' @param conn A database connection. +#' @param schema A string with schema name. +#' @param table A string with table name. +#' +#' @return +#' A reference to a database table. +#' +#' @importFrom dbplyr in_schema +#' @importFrom dplyr tbl +db_table <- function(conn, schema, table) { + tbl(conn, in_schema(schema, table)) +} diff --git a/R/dbutils.R b/R/fetch_db.R similarity index 50% rename from R/dbutils.R rename to R/fetch_db.R index 6fc4a33..02f184c 100644 --- a/R/dbutils.R +++ b/R/fetch_db.R @@ -1,19 +1,3 @@ -#' @export -#' @title Create a tbl that references a schema.table in the `conn` database. -#' -#' @param conn A database connection. -#' @param schema A string with schema name. -#' @param table A string with table name. -#' -#' @return -#' A reference to a database table. -#' -#' @importFrom dbplyr in_schema -#' @importFrom dplyr tbl -db_table <- function(conn, schema, table) { - tbl(conn, in_schema(schema, table)) -} - #' @export #' @title Fetch data from db #' @@ -43,14 +27,3 @@ fetch_db <- function(conn, path, ...) { stop(e) }) } - -#' @export -#' @title Transform a vector into a SQL-interpreted array. -#' -#' @param vector character vector -#' @return -#' List with a single string that's interpreted as a SQL array to interpolate in a query. -as_sql_array <- function(vector) { - array <- paste0("(", paste(paste0("'", vector, "'"), collapse = ", "), ")") - list(array) -} diff --git a/man/as_sql_array.Rd b/man/as_sql_array.Rd index 6b1ced5..7953eb6 100644 --- a/man/as_sql_array.Rd +++ b/man/as_sql_array.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dbutils.R +% Please edit documentation in R/as_sql_array.R \name{as_sql_array} \alias{as_sql_array} \title{Transform a vector into a SQL-interpreted array.} @@ -12,3 +12,6 @@ as_sql_array(vector) \value{ List with a single string that's interpreted as a SQL array to interpolate in a query. } +\description{ +Transform a vector into a SQL-interpreted array. +} diff --git a/man/db_table.Rd b/man/db_table.Rd index 6480e2a..31a3eb0 100644 --- a/man/db_table.Rd +++ b/man/db_table.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dbutils.R +% Please edit documentation in R/db_table.R \name{db_table} \alias{db_table} \title{Create a tbl that references a schema.table in the `conn` database.} @@ -16,3 +16,6 @@ db_table(conn, schema, table) \value{ A reference to a database table. } +\description{ +Create a tbl that references a schema.table in the `conn` database. +}