Added a new function called doc_upsert() that updates an existing document or creates it if it doesn't yet exist.
Description
doc_upsert() first retrieves the latest revision number for a given document id (docid) -- using db_revisions()
It then updates that document to the given doc -- using doc_update()
If the docid does not exist, then the first step will fail.
This is handled in doc_upsert(), which reverts to creating the document -- using doc_create()
Added a new function called
doc_upsert()
that updates an existing document or creates it if it doesn't yet exist.Description
doc_upsert()
first retrieves the latest revision number for a given document id (docid
) -- usingdb_revisions()
It then updates that document to the given
doc
-- usingdoc_update()
If the
docid
does not exist, then the first step will fail.This is handled in
doc_upsert()
, which reverts to creating the document -- usingdoc_create()
Example
Tests
doc_upsert()
is using existingsofa
functions.Nevertheless I included unit tests in the
tests/testthat
folder.