ropensci / sofa

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

update couchdb wiki R section at some point #41

Closed sckott closed 7 years ago

sckott commented 7 years ago

https://cwiki.apache.org/confluence/display/COUCHDB/R

katsel commented 7 years ago

I'd volunteer to do that!

Is there any new information that should be added, besides updating the code examples to reflect the current status of sofa?

katsel commented 7 years ago

Updated. Please let me know if there's anything else that needs to be added or changed.

sckott commented 7 years ago

hi @katsel - thanks!

I'm changing the pkg a lot, updating it to work with Couchdb v2, and a new way to set the connection. changes are on the branch https://github.com/ropensci/sofa/tree/r6setup I'm nearly done, and will then merge into master - I'll get a tutorial ready too, and ping here , which will have lots of egs. can use in the CouchDB wiki

sckott commented 7 years ago

@katsel I am trying to edit the wiki page, but can't edit it I don't think. I can give some things to add for you to do, or maybe I can get access?

katsel commented 7 years ago

@sckott I'm not an ASF member and I don't have commiter status with CouchDB, so I cannot grant any access rights. I do have edit rights for my own cwiki account though, so if that helps, I could make the changes for you.

sckott commented 7 years ago

that'd be great if you could make changes, thanks! here's what I'd like put in there in place of what's there now:

Description

An easy interface to CouchDB from R. Targeted at CouchDB v2+, but much of the package should work with older versions.

Installation

install.packages("sofa")

The below examples assume CouchDB running on http://localhost:5984

Load the package

library('sofa')

Make a client

client <- Cushion$new()
<sofa - cushion> 
  transport: http
  host: 127.0.0.1
  port: 5984
  path: 
  type: 
  user: 
  pwd:

Ping the server

ping(client)
$couchdb
[1] "Welcome"

$version
[1] "2.0.0"

$vendor
$vendor$name
[1] "The Apache Software Foundation"

Create a new database

db_create(client, dbname = 'cats')
$ok
[1] TRUE

List available databases

db_list(client)
[1] "cats"

Create a document

doc1 <- '{"name":"leo", "type":"cat", "color": "red"}'
doc_create(client, doc1, dbname = "cats", docid = "doc1")
$ok
[1] TRUE

$id
[1] "doc1"

$rev
[1] "1-a48c98c945bcc05d482bc6f938c89882"

Search

Search for cats that are red

db_query(client, dbname = "cats", selector = list(color = "red"))$docs
[[1]]
[[1]]$`_id`
[1] "e6bb43092edaf8fd987434b8a30cfbdf"

[[1]]$`_rev`
[1] "1-08aef850a23f5ff95869c9cf5d9604dc"

[[1]]$name
[1] "leo"

[[1]]$color
[1] "red"

[[1]]$type
[1] "cat"

Bulk create documents

Create documents in bulk from a data.frame, list, or JSON as a character string.

db_create(client, dbname = "bulktest")
db_bulk_create(client, dbname = "bulktest", mtcars)
katsel commented 7 years ago

Awesome! I just updated the wiki with the new version. I have taken the liberty of replacing "Search" with "Query the database", as it seems like a more suitable phrasing from my perspective . Thanks for putting all the work into this. I can confirm that the tutorial works as intended (tested with CouchDB 1.6).

sckott commented 7 years ago

Great. Thanks very much @katsel !