# NOT RUN {
# Create a CouchDB connection client
user <- Sys.getenv("COUCHDB_TEST_USER")
pwd <- Sys.getenv("COUCHDB_TEST_PWD")
(x <- Cushion$new(user=user, pwd=pwd))
## metadata
x$host
x$path
x$port
x$type
## ping the CouchDB server
x$ping()
## get CouchDB version
x$version()
# create database
if (!"stuff" %in% db_list(x)) {
db_create(x, "stuff")
}
# add documents to a database
if (!"sofadb" %in% db_list(x)) {
db_create(x, "sofadb")
}
doc1 <- '{"name": "drink", "beer": "IPA", "score": 5}'
doc_create(x, dbname="sofadb", docid="abeer", doc1)
# bulk create
if (!"mymtcars" %in% db_list(x)) {
db_create(x, "mymtcars")
}
db_bulk_create(x, dbname="mymtcars", doc = mtcars)
db_list(x)
## database info
db_info(x, "mymtcars")
## list dbs
db_list(x)
## all docs
db_alldocs(x, "mymtcars", limit = 3)
## changes
db_changes(x, "mymtcars")
# With auth
# x <- Cushion$new(user = 'sckott', pwd = 'sckott')
# Using Cloudant
# z <- Cushion$new(host = "ropensci.cloudant.com", transport = 'https', port = NULL,
# user = 'ropensci', pwd = Sys.getenv('CLOUDANT_PWD'))
# z
# db_list(z)
# db_create(z, "stuff2")
# db_info(z, "stuff2")
# db_alldocs(z, "foobar")
# }
Run the code above in your browser using DataLab