Upload (replicate) a local database to a remote database server, e.g., Cloudant, Iriscouch

Share:

Description

Upload (replicate) a local database to a remote database server, e.g., Cloudant, Iriscouch

Usage

1
db_replicate(from, to, dbname, createdb = FALSE, as = "list", ...)

Arguments

from

Couch to replicate from. An object of class Cushion. Required.

to

Remote couch to replicate to. An object of class Cushion. Required.

dbname

(character) Database name. Required.

createdb

If TRUE, the function creates the db on the remote server before uploading. The db has to exist before uploading, so either you do it separately or this fxn can do it for you. Default: FALSE

as

(character) One of list (default) or json

...

Curl args passed on to GET

Value

JSON as a character string or a list (determined by the as parameter)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## Not run: 
## create a connection
(x <- Cushion$new())

# Create a database locally
db_list(x)
if ("hello_earth" %in% db_list(x)) {
  invisible(db_delete(x, dbname="hello_earth"))
}
db_create(x, 'hello_earth')

## replicate to a remote server
z <- Cushion$new(host = "ropensci.cloudant.com", transport = 'https',
  port = NULL, user = 'ropensci', pwd = Sys.getenv('CLOUDANT_PWD'))

## do the replication
db_replicate(x, z, dbname = "hello_earth", createdb = TRUE)

## check changes on the remote
db_list(z)
changes(z, dbname = "hello_earth")

## make some changes on the remote
doc_create(z, dbname = "hello_earth",
  '{"language":"python","library":"requests"}', 'stuff')
changes(z, dbname = "hello_earth")

## create another document, and try to get it
doc_create(z, dbname = "hello_earth", doc = '{"language":"R"}',
  docid="R_rules")
doc_get(z, dbname = "hello_earth", docid='R_rules')

## cleanup - delete the database
db_delete(z, 'hello_earth')

## End(Not run)