diff --git a/R4CouchDB/R/cdbIni.R b/R4CouchDB/R/cdbIni.R index 43cec1c..bfc4bdd 100644 --- a/R4CouchDB/R/cdbIni.R +++ b/R4CouchDB/R/cdbIni.R @@ -11,6 +11,7 @@ cdbIni <- function(){ port = "5984", DBName="", newDBName="", + removeDBName="", id="", rev="", dataList=list(), diff --git a/R4CouchDB/R/cdbListDB.R b/R4CouchDB/R/cdbListDB.R index fd89354..de04c73 100644 --- a/R4CouchDB/R/cdbListDB.R +++ b/R4CouchDB/R/cdbListDB.R @@ -1,17 +1,17 @@ cdbListDB <- function(cdb){ - + if(cdb$serverName == ""){ - cdb$error <- paste(cdb$error," no cdb$serverName given") - } - if(cdb$error == ""){ - adrString <- paste("http://", - cdb$serverName,":", - cdb$port, "/_all_dbs", - sep="") + cdb$error <- paste(cdb$error," no cdb$serverName given") + } + if(cdb$error == ""){ + adrString <- paste("http://", + cdb$serverName,":", + cdb$port, "/_all_dbs", + sep="") - res <- getURL(adrString) - cdb$res <- fromJSON(res) - return( cdb ) + res <- getURL(adrString) + cdb$res <- fromJSON(res) + return( cdb ) }else{ print(cdb$error) return( cdb ) diff --git a/R4CouchDB/R/cdbRemoveDB.R b/R4CouchDB/R/cdbRemoveDB.R index 7cbe816..2e2b77c 100644 --- a/R4CouchDB/R/cdbRemoveDB.R +++ b/R4CouchDB/R/cdbRemoveDB.R @@ -1,25 +1,45 @@ cdbRemoveDB <- function(cdb){ + + if(cdb$serverName == ""){ + cdb$error <- paste(cdb$error," no cdb$serverName given") + } + + if(cdb$removeDBName == ""){ + cdb$error <- paste(cdb$error, "no cdb$removeDBName given") + }else{ + + DBNames <- cdbListDB(cdb)$res + DBexists <- which(DBNames == cdb$removeDBName) + + if(length(DBexists) == 0){ + + cdb$error <- paste(cdb$error, + " there is no cdb$removeDBName to delete") + + } + } + if( cdb$error == ""){ - if(cdb$DBName == ""){ + adrString <- paste("http://", + cdb$serverName,":", + cdb$port,"/", + cdb$removeDBName, + sep="") - cdb$error <- "no cdb$DBName to remove" - return(cdb) - }else{ + res <- getURLContent(adrString, + .opts = list(customrequest = "DELETE") + ) - adrString <- paste("http://", - cdb$serverName,":", - cdb$port,"/", - cdb$DBName, - sep="") + cdb$res <- fromJSON(res) - res <- getURLContent(adrString, .opts = list(customrequest = "DELETE")) - cdb$res <- fromJSON(res) - cdb$DBName <- "" + ## the DB should be history + cdb$removeDBName <- "" return( cdb ) - } + }else{ - return(cdb) - } + print(cdb$error) + return(cdb) + } }