Permalink
Browse files

new internal function `cdb$getDocRev`

requests the revision

	geändert:   R4CouchDB/DESCRIPTION
	geändert:   R4CouchDB/R/cdbIni.R
	geändert:   R4CouchDB/R/cdbUpdateDoc.R
	geändert:   R4CouchDB/man/cdbUpdateDoc.Rd
	neue Datei:   R4CouchDB_0.3.tar.gz
  • Loading branch information...
wactbprot committed Sep 13, 2013
1 parent da5180f commit fd977726904f851b7c493a48d4a443c611f7f0a5
View
@@ -1,14 +1,16 @@
Package: R4CouchDB
Type: Package
Title: A R convenience layer for CouchDB
-Version: 0.2.5
-Date: 2013/09/05
+Version: 0.3
+Date: 2013/09/13
Author: wactbprot
Maintainer: <thsteinbock@web.de>
Description: The R4CouchDB package provides a collection of functions for
basic database and document management operations such as add and
delete. Every cdbFunction() gets and returns a list() containing the
- connection setup. Such a list can be generated by cdbIni().
+ connection setup. Such a list (in the documentation mostly called cdb)
+ can be generated by cdb <- cdbIni(). Then cdb also contains some function
+ resp. functionality e.g cdb$baseUrl().
License: BSD
LazyLoad: yes
Depends:
View
@@ -133,7 +133,14 @@ cdbIni <- function(serverName = "localhost",
jsn <- gsub("\\r","\\\\r",jsn)
return(jsn)
}
-
+ cdb$getDocRev <- function(cdb){
+ adrString <- paste(cdb$baseUrl(cdb),
+ cdb$DBName,"/",
+ cdb$id,
+ sep="")
+ res <- url.exists(adrString, .header=TRUE)
+ return(paste("",gsub("\\\"", "", res["ETag"]), sep=""))
+ }
cdb$checkRes <- function(cdb,res){
if(!(cdb$error == "")){
stop( paste("local error:", cdb$error))
View
@@ -2,18 +2,18 @@
#'
#' This essentially means that a
#' revision, corresponding to the '_id' has to be provided. If no '_rev' is
-#' provided the function gets the doc fron the db and takes the revition number
-#' for the update
-#'
+#' given in the \code{cdb} list the function gets the doc from the db
+#' and takes the rev number for the update
+#'
#' Updating a doc at couchdb means executing a http "PUT" request. The
#' \code{cdb} list must contain the \code{cdb$serverName}, \code{cdb$port},
#' \code{cdb$DBName}, \code{cdb$id}. Since v0.6 the revision of the document
-#' should exist at the intended place; \code{cdb$dataList$'_rev'}.
-#'
+#' should exist at the intended place: \code{cdb$dataList$'_rev'}.
+#'
#' \code{getURL()} with \code{customrequest = "PUT"} does the work. If a
#' needed \code{cdb$} list entry is not provided \code{cdb$error} maybe says
#' something about the R side.
-#'
+#'
#' @usage cdbUpdateDoc(cdb)
#' @param cdb the cdb connection configuration list must contain the
#' \code{cdb$serverName}, \code{cdb$port}, \code{cdb$DBName} and \code{cdb$id}.
@@ -32,32 +32,39 @@
#'
cdbUpdateDoc <- function( cdb){
-
- fname <- deparse(match.call()[[1]])
- cdb <- cdb$checkCdb(cdb,fname)
-
- if( cdb$error ==""){
-
- adrString <- paste(cdb$baseUrl(cdb),
- cdb$DBName,"/",
- cdb$id,
- sep="")
-
- res <- getURL(customrequest = "PUT",
- curl=cdb$curl,
- url = adrString,
- postfields = cdb$toJSON(cdb$dataList),
- httpheader=c('Content-Type: application/json;charset=utf-8'),
- .opts =cdb$opts(cdb))
-
- cdb <- cdb$checkRes(cdb,res)
-
- if((length(cdb$res$ok)) > 0 ){
- cdb$dataList$'_rev' <- cdb$res$rev
- cdb$rev <- cdb$res$rev
+
+ fname <- deparse(match.call()[[1]])
+ cdb <- cdb$checkCdb(cdb,fname)
+
+ if(length(cdb$dataList[["_rev"]]) < 1){
+ rev <- cdb$getDocRev(cdb)
+ if(!is.na(rev)){
+ cdb$dataList[["_rev"]] <- rev
+ }
+ }
+
+ if( cdb$error ==""){
+
+ adrString <- paste(cdb$baseUrl(cdb),
+ cdb$DBName,"/",
+ cdb$id,
+ sep="")
+
+ res <- getURL(customrequest = "PUT",
+ curl=cdb$curl,
+ url = adrString,
+ postfields = cdb$toJSON(cdb$dataList),
+ httpheader=c('Content-Type: application/json;charset=utf-8'),
+ .opts =cdb$opts(cdb))
+
+ cdb <- cdb$checkRes(cdb,res)
+
+ if((length(cdb$res$ok)) > 0 ){
+ cdb$dataList$'_rev' <- cdb$res$rev
+ cdb$rev <- cdb$res$rev
+ }
+ return(cdb)
+ }else{
+ stop(cdb$error)
}
- return(cdb)
- }else{
- stop(cdb$error)
- }
}
@@ -19,16 +19,16 @@
}
\description{
This essentially means that a revision, corresponding to
- the '_id' has to be provided. If no '_rev' is provided
- the function gets the doc fron the db and takes the
- revition number for the update
+ the '_id' has to be provided. If no '_rev' is given in
+ the \code{cdb} list the function gets the doc from the db
+ and takes the rev number for the update
}
\details{
Updating a doc at couchdb means executing a http "PUT"
request. The \code{cdb} list must contain the
\code{cdb$serverName}, \code{cdb$port},
\code{cdb$DBName}, \code{cdb$id}. Since v0.6 the revision
- of the document should exist at the intended place;
+ of the document should exist at the intended place:
\code{cdb$dataList$'_rev'}.
\code{getURL()} with \code{customrequest = "PUT"} does
View
Binary file not shown.

0 comments on commit fd97772

Please sign in to comment.