ropensci / sofa

Easy R interface to CouchDB
https://docs.ropensci.org/sofa/
33 stars 17 forks source link

Include 'as' argument in doc_upsert #79

Closed procface closed 2 years ago

procface commented 3 years ago

Description

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')

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

maelle commented 2 years ago

This repository is about to be archived.