Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7a6bcdb
Showing
28 changed files
with
3,608 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Package: octopus | ||
Type: Package | ||
Title: A Database Management Tool | ||
Version: 0.1.2 | ||
Authors@R: person("Marcus", "Codrescu", , "m.codrescu@outlook.com", role = c("aut", "cre")) | ||
Maintainer: Marcus Codrescu <m.codrescu@outlook.com> | ||
Description: A database management tool built as a 'shiny' application. Connect to various | ||
databases to send queries, upload files, preview tables, and more. | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
Suggests: duckdb, keyring, odbc, readr, RMySQL, RPostgres, RSQLite, | ||
testthat (>= 3.0.0) | ||
Config/testthat/edition: 3 | ||
Imports: bslib, DBI, dplyr, DT, glue, httr, janitor, rio, shiny, | ||
shinyAce, shinyjs, utils | ||
RoxygenNote: 7.2.1 | ||
NeedsCompilation: no | ||
Packaged: 2023-03-22 02:20:22 UTC; mc678p | ||
Author: Marcus Codrescu [aut, cre] | ||
Repository: CRAN | ||
Date/Publication: 2023-03-22 09:30:05 UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2023 | ||
COPYRIGHT HOLDER: octopus authors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
469d536bb115f26b9f3e2706d4e3fad0 *DESCRIPTION | ||
3e1863b11eeb4064746c5621d02ee3b5 *LICENSE | ||
05ecbebff9cf3b09dfc7371aab85c228 *NAMESPACE | ||
5881f8ceddd4f99c01c3c917ea6cd800 *R/duckdb_connection.R | ||
367fb27250d764a6e51c96d8be95d20a *R/get_database_functions.R | ||
86c2e907d985204877e1bf0a2daca740 *R/list_drivers.R | ||
bdc8850a82cbb2e519eb89a15079378d *R/mysql_connection.R | ||
da906db3adb62f15c7387a18394c2ae2 *R/postgres_connection.R | ||
7e57d5b94129cc1d5a661c860f894817 *R/snowflake_connection.R | ||
3f599c544cd113f9096a4df584a7c18d *R/sqlite_connection.R | ||
3d294a35010d3b37b6e48bad79e18556 *R/submit_query.R | ||
0f591c8e2e4f4a3a1ac35ba56d7e3513 *R/table_modal_w_download.R | ||
a49d8894e75861df9f6b99a87366910c *R/vertica_connection.R | ||
2fc0c509049f76366941bfad4b75e928 *R/view_database.R | ||
fbe4ac7e45949197fdb90c7b3c116472 *README.md | ||
d1474ddceea47e984eecb41867997494 *man/list_drivers.Rd | ||
8ff237823b0797721426490f227c8f17 *man/view_database.Rd | ||
2cdc915fcce6cb2afcfe9c42c75118a3 *tests/testthat.R | ||
9162a50b22f38c596c31497507b38964 *tests/testthat/test-duckdb_connection.R | ||
7f792314138b019f389572c8bb5a22be *tests/testthat/test-list_drivers.R | ||
737544f33d7b91ab0066ea4a42857d68 *tests/testthat/test-mysql_connection.R | ||
f1bcd36e3767639c2c8df4f36f86b6c8 *tests/testthat/test-postgres_connection.R | ||
d7e2abfde199f8cefac0ea80fa64df99 *tests/testthat/test-snowflake_connection.R | ||
0b1c94c23d404b1aea8e48db1314ffdd *tests/testthat/test-sqlite_connection.R | ||
aba724e504ec003d87146be2a73b0119 *tests/testthat/test-submit_query.R | ||
fe9ca6b58d7265c7a5036adc340db94b *tests/testthat/test-vertica_connection.R | ||
dc8aaf850254b9301cc85585aeab0b61 *tests/testthat/test-view_database.R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(list_drivers) | ||
export(view_database) | ||
importFrom(DBI,Id) | ||
importFrom(DBI,dbClearResult) | ||
importFrom(DBI,dbGetQuery) | ||
importFrom(DBI,dbListTables) | ||
importFrom(DBI,dbSendQuery) | ||
importFrom(DBI,dbWriteTable) | ||
importFrom(DT,renderDataTable) | ||
importFrom(bslib,bs_theme) | ||
importFrom(dplyr,pull) | ||
importFrom(glue,glue) | ||
importFrom(httr,GET) | ||
importFrom(httr,content) | ||
importFrom(httr,use_proxy) | ||
importFrom(janitor,clean_names) | ||
importFrom(rio,import) | ||
importFrom(shiny,NS) | ||
importFrom(shiny,bootstrapPage) | ||
importFrom(shiny,div) | ||
importFrom(shiny,downloadButton) | ||
importFrom(shiny,downloadHandler) | ||
importFrom(shiny,fileInput) | ||
importFrom(shiny,h3) | ||
importFrom(shiny,modalButton) | ||
importFrom(shiny,modalDialog) | ||
importFrom(shiny,moduleServer) | ||
importFrom(shiny,observeEvent) | ||
importFrom(shiny,p) | ||
importFrom(shiny,removeModal) | ||
importFrom(shiny,req) | ||
importFrom(shiny,selectInput) | ||
importFrom(shiny,shinyApp) | ||
importFrom(shiny,showModal) | ||
importFrom(shiny,showNotification) | ||
importFrom(shiny,stopApp) | ||
importFrom(shiny,tagList) | ||
importFrom(shiny,tags) | ||
importFrom(shiny,updateSelectInput) | ||
importFrom(shiny,updateSelectizeInput) | ||
importFrom(shinyAce,aceEditor) | ||
importFrom(shinyAce,updateAceEditor) | ||
importFrom(shinyjs,hideElement) | ||
importFrom(shinyjs,html) | ||
importFrom(shinyjs,onclick) | ||
importFrom(shinyjs,onevent) | ||
importFrom(shinyjs,showElement) | ||
importFrom(shinyjs,useShinyjs) | ||
importFrom(utils,write.csv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
#' A Database Specific Function To Retrieve Database Schemas | ||
#' @noRd | ||
#' | ||
#' @param con A database connection object. | ||
#' | ||
#' @importFrom DBI dbGetQuery | ||
#' @importFrom dplyr pull | ||
#' | ||
#' @return A character vector of all schemas in the database. | ||
get_schemas_duckdb <- function(con) { | ||
|
||
DBI::dbGetQuery( | ||
con, | ||
" | ||
SELECT DISTINCT schema_name | ||
FROM information_schema.schemata | ||
" | ||
) |> | ||
dplyr::pull(1) | ||
} | ||
|
||
#' A Database Specific Function to Retrieve All Database Tables | ||
#' @noRd | ||
#' | ||
#' @param con A database connection object. | ||
#' @param schema A | ||
#' | ||
#' @importFrom DBI dbListTables | ||
#' | ||
#' @return A character vector of all tables in a given schema. | ||
get_tables_duckdb <- function(con, schema) { | ||
|
||
DBI::dbGetQuery( | ||
con, | ||
glue::glue( | ||
" | ||
SELECT table_name | ||
FROM information_schema.tables | ||
WHERE table_schema = '{schema}' | ||
" | ||
) | ||
) |> | ||
dplyr::pull(1) | ||
|
||
} | ||
|
||
#' A Database Specific Function to Retrieve the Number of Rows of a Table | ||
#' @noRd | ||
#' | ||
#' @param con A database connection object. | ||
#' @param schema A string containing the schema name. | ||
#' @param table A string containing the table name. | ||
#' @param query A string containing the query to send. | ||
#' | ||
#' @importFrom DBI dbGetQuery | ||
#' @importFrom glue glue | ||
#' @importFrom dplyr pull | ||
#' | ||
#' @return An integer for the number of rows in the table. | ||
get_n_rows_duckdb <- function(con, schema, table, query = "") { | ||
|
||
if (query != ""){ | ||
if (!grepl("^SELECT", trimws(query), ignore.case = TRUE)){ | ||
return(0) | ||
} | ||
query_string <- | ||
glue::glue( | ||
" | ||
SELECT COUNT(*) AS count | ||
FROM ( | ||
{query} | ||
) AS subquery | ||
" | ||
) | ||
} else { | ||
query_string <- | ||
glue::glue( | ||
" | ||
SELECT COUNT(*) AS count | ||
FROM ( | ||
SELECT * | ||
FROM \"{schema}\".\"{table}\" | ||
) AS subquery; | ||
" | ||
) | ||
} | ||
|
||
DBI::dbGetQuery( | ||
con, | ||
query_string | ||
) |> | ||
dplyr::pull(1) | ||
|
||
|
||
} | ||
|
||
#' A Database Specific Function for Retrieving Table Previews | ||
#' @noRd | ||
#' | ||
#' @param con A database connection object. | ||
#' @param schema A string containing the schema name. | ||
#' @param table A string containing the table name. | ||
#' | ||
#' @importFrom DBI dbGetQuery | ||
#' @importFrom glue glue | ||
#' | ||
#' @return A data frame of 100 rows from the database table. | ||
get_preview_duckdb <- function(con, schema, table) { | ||
DBI::dbGetQuery( | ||
con, | ||
glue::glue( | ||
" | ||
SELECT * | ||
FROM \"{schema}\".\"{table}\" | ||
LIMIT 100; | ||
" | ||
) | ||
) | ||
} | ||
|
||
|
||
#' A Database Specific Function for Dropping Tables | ||
#' @noRd | ||
#' | ||
#' @param con A database connection object. | ||
#' @param schema A string containing the schema name. | ||
#' @param table A string containing the table name. | ||
#' | ||
#' @importFrom DBI dbSendQuery | ||
#' @importFrom DBI dbClearResult | ||
#' @importFrom glue glue | ||
#' | ||
#' @return A result string. Either "Success" or an error message. | ||
delete_table_duckdb <- function(con, schema, table){ | ||
|
||
DBI::dbSendQuery( | ||
con, | ||
glue::glue( | ||
"DROP TABLE \"{schema}\".\"{table}\"" | ||
) | ||
) |> | ||
DBI::dbClearResult() | ||
|
||
"Success" | ||
|
||
} | ||
|
||
|
||
#' A Database Specific Function for Uploading Data Frames | ||
#' @noRd | ||
#' | ||
#' @param con A database connection object. | ||
#' @param schema A string containing the schema name. | ||
#' @param table_name A string for the new table name. | ||
#' @param data A data frame to be uploaded. | ||
#' @param temporary A logical value. Should the table be temporary? | ||
#' | ||
#' @importFrom DBI dbWriteTable | ||
#' @importFrom DBI dbSendQuery | ||
#' @importFrom DBI dbClearResult | ||
#' | ||
#' @return A result string. Either "Success" or an error message. | ||
write_table_duckdb <- | ||
function( | ||
con, | ||
schema, | ||
table_name, | ||
data, | ||
temporary = FALSE | ||
){ | ||
|
||
DBI::dbSendQuery( | ||
con, | ||
glue::glue( | ||
"SET SEARCH_PATH TO '{schema}'" | ||
) | ||
) |> | ||
DBI::dbClearResult() | ||
|
||
DBI::dbWriteTable( | ||
con, | ||
name = table_name, | ||
value = data.frame(data), | ||
overwrite = TRUE, | ||
temporary = temporary | ||
) | ||
|
||
"Success" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#' Get Database Driver Specific Functions | ||
#' @noRd | ||
#' | ||
#' @param driver A string database connection driver name. | ||
#' | ||
#' @return A list of database specific functions. | ||
get_database_functions <- | ||
function( | ||
driver | ||
){ | ||
if (driver == "PqConnection"){ | ||
return ( | ||
list( | ||
get_schemas_postgres, | ||
get_tables_postgres, | ||
get_n_rows_postgres, | ||
get_preview_postgres, | ||
delete_table_postgres, | ||
write_table_postgres | ||
) | ||
) | ||
|
||
} else if (driver == "Snowflake"){ | ||
return ( | ||
list( | ||
get_schemas_snowflake, | ||
get_tables_snowflake, | ||
get_n_rows_snowflake, | ||
get_preview_snowflake, | ||
delete_table_snowflake, | ||
write_table_snowflake | ||
) | ||
) | ||
|
||
} else if (driver == "Vertica Database"){ | ||
return ( | ||
list( | ||
get_schemas_vertica, | ||
get_tables_vertica, | ||
get_n_rows_vertica, | ||
get_preview_vertica, | ||
delete_table_vertica, | ||
write_table_vertica | ||
) | ||
) | ||
|
||
} else if (driver == "duckdb_connection"){ | ||
return ( | ||
list( | ||
get_schemas_duckdb, | ||
get_tables_duckdb, | ||
get_n_rows_duckdb, | ||
get_preview_duckdb, | ||
delete_table_duckdb, | ||
write_table_duckdb | ||
) | ||
) | ||
|
||
} else if (driver == "MySQLConnection"){ | ||
return ( | ||
list( | ||
get_schemas_mysql, | ||
get_tables_mysql, | ||
get_n_rows_mysql, | ||
get_preview_mysql, | ||
delete_table_mysql, | ||
write_table_mysql | ||
) | ||
) | ||
|
||
} else if (driver == "SQLiteConnection"){ | ||
return ( | ||
list( | ||
get_schemas_sqlite, | ||
get_tables_sqlite, | ||
get_n_rows_sqlite, | ||
get_preview_sqlite, | ||
delete_table_sqlite, | ||
write_table_sqlite | ||
) | ||
) | ||
|
||
} else if (driver == "FaultyConnectionExample"){ | ||
return ( | ||
list( | ||
\(con) stop("This is a get_schemas error"), | ||
\(con, schema) stop("This is a get_tables error"), | ||
\(con, schema, table, query) stop("This is a get_n_rows error"), | ||
\(con, schema, table) stop("This is a get_preview error"), | ||
\(con, schema, table) stop("This is a delete_table error"), | ||
\(con, schema, table_name, data, temporary) stop("This is a write_table error") | ||
) | ||
) | ||
|
||
} else { | ||
stop( | ||
"Database driver not found. | ||
Please use octopus::list_drivers() to see a list of all available drivers. | ||
" | ||
) | ||
} | ||
} |
Oops, something went wrong.