Learn R Programming

sofa (version 0.2.0)

db_changes: List changes to a database.

Description

Of course it doesn't make much sense to use certain options in _changes. For example, using feed=longpoll or continuous doesn't make much sense within R itself.

Usage

db_changes(cushion, dbname, descending = NULL, startkey = NULL, endkey = NULL, since = NULL, limit = NULL, include_docs = NULL, feed = "normal", heartbeat = NULL, filter = NULL, as = "list", ...)

Arguments

cushion
A Cushion object. Required.
dbname
Database name. (charcter)
descending
Return in descending order? (logical)
startkey
Document ID to start at. (character)
endkey
Document ID to end at. (character)
since
Start the results from the change immediately after the given sequence number.
limit
Number document IDs to return. (numeric)
include_docs
(character) If "true", returns docs themselves, in addition to IDs
feed
Select the type of feed. One of normal, longpoll, or continuous. See description. (character)
heartbeat
Period in milliseconds after which an empty line is sent in the results. Only applicable for longpoll or continuous feeds. Overrides any timeout to keep the feed alive indefinitely. (numeric (milliseconds))
filter
Reference a filter function from a design document to selectively get updates.
as
(character) One of list (default) or json
...
Curl args passed on to one of the HTTP verbs (e.g,. GET, POST, PUT, etc.)

Value

Either a list of json (depending on as parameter), with keys:
  • results - Changes made to a database, length 0 if no changes. Each of these has:
    • changes - List of document`s leafs with single field rev
    • id - Document ID
    • seq - Update sequence
  • last_seq - Last change update sequence
  • pending - Count of remaining items in the feed

Examples

Run this code
## Not run: 
# (x <- Cushion$new())
# 
# if ("leothelion" %in% db_list(x)) {
#   invisible(db_delete(x, dbname="leothelion"))
# }
# db_create(x, dbname='leothelion')
# 
# # no changes
# res <- db_changes(x, dbname="leothelion")
# res$results
# 
# # create a document
# doc1 <- '{"name": "drink", "beer": "IPA", "score": 5}'
# doc_create(x, dbname="leothelion", doc1, docid="abeer")
# 
# # now there's changes
# res <- db_changes(x, dbname="leothelion")
# res$results
# 
# # as JSON
# db_changes(x, dbname="leothelion", as='json')
# ## End(Not run)

Run the code above in your browser using DataLab