The doc_upsert functions tries to update a document using the doc_update function and if that produces an error, creates a new document with doc_create. Both doc_update and doc_create allow an 'as' argument to define how the response is returned: either as a list or as a json. Thus, doc_upsert now allows the 'as' argument to be included and passes this argument to the other functions.
Related Issue
No related issue
Example
Direct usage of current doc_upsert example:
user <- Sys.getenv("COUCHDB_TEST_USER")
pwd <- Sys.getenv("COUCHDB_TEST_PWD")
(x <- Cushion$new(user=user, pwd=pwd))
if ("sofadb" %in% db_list(x)) {
invisible(db_delete(x, dbname="sofadb"))
}
db_create(x, 'sofadb')
Description
The
doc_upsert
functions tries to update a document using thedoc_update
function and if that produces an error, creates a new document withdoc_create
. Bothdoc_update
anddoc_create
allow an 'as' argument to define how the response is returned: either as a list or as a json. Thus, doc_upsert now allows the 'as' argument to be included and passes this argument to the other functions.Related Issue
No related issue
Example
Direct usage of current
doc_upsert
example:user <- Sys.getenv("COUCHDB_TEST_USER") pwd <- Sys.getenv("COUCHDB_TEST_PWD") (x <- Cushion$new(user=user, pwd=pwd))
if ("sofadb" %in% db_list(x)) { invisible(db_delete(x, dbname="sofadb")) } db_create(x, 'sofadb')
create a document
doc1 <- '{"name": "drink", "beer": "IPA", "score": 5}' doc_upsert(x, dbname="sofadb", doc1, docid="abeer")
update the document
doc2 <- '{"name": "drink", "beer": "lager", "score": 6}' doc_upsert(x, dbname="sofadb", doc2, docid="abeer", as = "json") doc_upsert(x, dbname="sofadb", doc1, docid="abeer", as = "list)
Tests included in tests/test-doc_upsert.R