diff --git a/DESCRIPTION b/DESCRIPTION index 5dfbe3e89..1cf0bfa1f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -79,7 +79,6 @@ Collate: 'query.R' 'regularExpressions.R' 'rownames.R' - 'rstudioConnections.R' 'table.R' 'transactions.R' 'utils.R' diff --git a/R/connect.R b/R/connect.R index 27a2ca800..2b7214b5f 100644 --- a/R/connect.R +++ b/R/connect.R @@ -203,9 +203,6 @@ setMethod("dbConnect", "SQLiteDriver", } ) - # rstudio connections tab - on_connection_opened(conn) - conn } ) @@ -258,9 +255,5 @@ setMethod("dbConnect", "SQLiteConnection", function(drv, ...) { #' @rdname SQLite setMethod("dbDisconnect", "SQLiteConnection", function(conn, ...) { connection_release(conn@ptr) - - # rstudio connections tab - on_connection_closed(conn) - invisible(TRUE) }) diff --git a/R/rstudioConnections.R b/R/rstudioConnections.R deleted file mode 100644 index 4a0a8ba3a..000000000 --- a/R/rstudioConnections.R +++ /dev/null @@ -1,155 +0,0 @@ -# Functions used to connect to Connections Pane in Rstudio -# Implementing connections contract: https://rstudio.github.io/rstudio-extensions/connections-contract.html -sqlite_ListObjectTypes <- function(con) { - object_types <- list(table = list(contains = "data")) - - types <- dbGetQuery(con, "SELECT DISTINCT type FROM sqlite_master")[[1]] - if (any(types == "view")) { - object_types <- c(object_types, view = list(contains = "data")) - } - object_types -} - -sqlite_ListObjects <- function(con, catalog = NULL, schema = NULL, name = NULL, type = NULL, ...) { - objects <- dbGetQuery(con, "SELECT name,type FROM sqlite_master") - objects <- objects[objects$type %in% c("table", "view"), ] - objects -} - -sqlite_ListColumns <- function(con, table = NULL, view = NULL, - catalog = NULL, schema = NULL, ...) { - if (is.null(table)) { - table <- view - } - - tb <- dbGetQuery( - con, - paste("SELECT * FROM", dbQuoteIdentifier(con, table), "WHERE FALSE") - ) - - name <- names(tb) - type <- sapply(tb, class) - - data.frame( - name = name, - type = type, - stringsAsFactors = FALSE - ) -} - -sqlite_PreviewObject <- function(con, rowLimit, table = NULL, view = NULL, ...) { - # extract object name from arguments - name <- if (is.null(table)) view else table - dbGetQuery(con, paste("SELECT * FROM", dbQuoteIdentifier(con, name)), n = rowLimit) -} - -sqlite_ConnectionIcon <- function(con) { - system.file("icons/sqlite.png", package = "RSQLite") -} - -sqlite_ConnectionActions <- function(con) { - actions <- list() - actions <- c(actions, list( - Help = list( - icon = "", - callback = function() { - utils::browseURL("https://rsqlite.r-dbi.org/") - } - ) - )) - - actions -} - - -get_host <- function(con) { - if (con@dbname == "") { - return("") - } - paste0("<", con@dbname, ">") -} - -##### Functions that trigger update in Rstudio Connections tab - -on_connection_opened <- function(con) { - observer <- getOption("connectionObserver") - if (is.null(observer)) { - return(invisible(NULL)) - } - - code <- paste0( - "library(DBI) -con <- dbConnect(RSQLite::SQLite(), dbname=\"", con@dbname, "\") -" - ) - icon <- sqlite_ConnectionIcon(con) - - host <- get_host(con) - - # let observer know that connection has opened - observer$connectionOpened( - # connection type - type = "RSQLite", - - # name displayed in connection pane (to be improved) - displayName = paste0( - "SQLite ", - host, - if (con@dbname == "") " (temporary)" - ), - host = host, - icon = icon, - - # connection code - connectCode = code, - - # disconnection code - disconnect = function() { - dbDisconnect(con, shutdown = TRUE) - }, - listObjectTypes = function() { - sqlite_ListObjectTypes(con) - }, - - # table enumeration code - listObjects = function(...) { - sqlite_ListObjects(con, ...) - }, - - # column enumeration code - listColumns = function(...) { - sqlite_ListColumns(con, ...) - }, - - # table preview code - previewObject = function(rowLimit, ...) { - sqlite_PreviewObject(con, rowLimit, ...) - }, - - # other actions that can be executed on this connection - actions = sqlite_ConnectionActions(con), - - # raw connection object - connectionObject = con - ) -} - -on_connection_updated <- function(con, hint) { - observer <- getOption("connectionObserver") - if (is.null(observer)) { - return(invisible(NULL)) - } - - host <- get_host(con) - observer$connectionUpdated("RSQLite", host, hint = hint) -} - -on_connection_closed <- function(con) { - observer <- getOption("connectionObserver") - if (is.null(observer)) { - return(invisible(NULL)) - } - - host <- get_host(con) - observer$connectionClosed("RSQLite", host) -} diff --git a/R/table.R b/R/table.R index 36871025f..4505d0a29 100644 --- a/R/table.R +++ b/R/table.R @@ -129,10 +129,6 @@ setMethod("dbWriteTable", c("SQLiteConnection", "character", "data.frame"), dbCommit(conn, name = savepoint_id) on.exit(NULL) - - # rstudio connections tab - on_connection_updated(conn, paste0("Updating table '", name, "'")) - invisible(TRUE) } ) @@ -242,10 +238,6 @@ setMethod("dbWriteTable", c("SQLiteConnection", "character", "character"), dbCommit(conn, name = savepoint_id) on.exit(NULL) - - # rstudio connections tab - on_connection_updated(conn, paste0("Updating table '", name, "'")) - invisible(TRUE) } ) @@ -370,10 +362,6 @@ setMethod("dbRemoveTable", c("SQLiteConnection", "character"), } dbExecute(conn, paste0("DROP TABLE ", extra, name)) - - # rstudio connections tab - on_connection_updated(conn, paste0("Removing table '", name, "'")) - invisible(TRUE) } ) diff --git a/inst/icons/sqlite.png b/inst/icons/sqlite.png deleted file mode 100644 index c113a9fff..000000000 Binary files a/inst/icons/sqlite.png and /dev/null differ diff --git a/inst/rstudio/connections.dcf b/inst/rstudio/connections.dcf deleted file mode 100644 index 0edc4ae7f..000000000 --- a/inst/rstudio/connections.dcf +++ /dev/null @@ -1,3 +0,0 @@ -Name: SQLite -HelpUrl: https://rsqlite.r-dbi.org/ -Icon: icons/sqlite.png diff --git a/inst/rstudio/connections/SQLite.R b/inst/rstudio/connections/SQLite.R deleted file mode 100644 index b4c5df7b8..000000000 --- a/inst/rstudio/connections/SQLite.R +++ /dev/null @@ -1,9 +0,0 @@ -library(RSQLite) - -con <- DBI::dbConnect(SQLite(), dbname = "${1:File name}") - -## Adding a table to the empty database -# DBI::dbWriteTable(con, "iris", iris) - -## Disconnecting... -# DBI::dbDisconnect(con)