Work with design documents

Description

Work with design documents

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
design_create(cushion, dbname, design, fxnname, key = "null", value = "doc",
  as = "list", ...)

design_create_(cushion, dbname, design, fxnname, fxn, as = "list", ...)

design_delete(cushion, dbname, design, as = "list", ...)

design_get(cushion, dbname, design, as = "list", ...)

design_head(cushion, dbname, design, ...)

design_info(cushion, dbname, design, ...)

design_copy(cushion, dbname, design, design_to, as = "list", ...)

Arguments

cushion

A Cushion object. Required.

dbname

(character) Database name. required.

design

(character) Design document name. this is the design name without _design/, which is prepended internally. required.

fxnname

(character) A function name. required for view_put and view_put_

key, value

(character) a key and value, see Examples and Details

as

(character) One of list (default) or json

...

Curl args passed on to one of the HTTP verbs (e.g,. GET, POST, PUT, etc.)

fxn

(character) a javascript function. required for view_put_

design_to

(character) Design document name. this is the design name without _design/, which is prepended internally. required for design_copy

Details

design_create is a slightly easier interface to creating design documents; it just asks for a function name, the key and a value, then we create the function for you internally. TO have more flexibility use view_put_ (with underscore on the end) to write the function yourself.

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
## Not run: 
(x <- Cushion$new())

file <- system.file("examples/omdb.json", package = "sofa")
strs <- readLines(file)

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

## add the documents
invisible(db_bulk_create(x, "omdb", strs))

# Create a view, the easy way, but less flexible
design_create(x, dbname='omdb', design='view1', fxnname="foobar1")
design_create(x, dbname='omdb', design='view2', fxnname="foobar2",
  value="doc.Country")
design_create(x, dbname='omdb', design='view5', fxnname="foobar3",
  value="[doc.Country,doc.imdbRating]")

# the harder way, write your own function, but more flexible
design_create_(x, dbname='omdb', design='view2',
  fxnname = "stuffthings", fxn = "function(doc){emit(null,doc.Country)}")

# Delete a view
design_delete(x, dbname='omdb', design='view1')

# Get info on a design document
## HEAD request, returns just response headers
design_head(x, dbname='omdb', design='view2')
design_head(x, dbname='omdb', design='view5')
## GET request, returns information about the design document
design_info(x, dbname='omdb', design='view2')
design_info(x, dbname='omdb', design='view5')

# Get a design document (GET request)
design_get(x, dbname='omdb', design='view2')
design_get(x, dbname='omdb', design='view5')

# Search using a view
res <- view_search(x, dbname='omdb', design='view2')
head(
  do.call(
    "rbind.data.frame",
    lapply(res$rows, function(x) Filter(length, x))
  )
)

res <- view_search(x, dbname='omdb', design='view5')
head(
  structure(do.call(
    "rbind.data.frame",
    lapply(res$rows, function(x) x$value)
  ), .Names = c('Country', 'imdbRating'))
)

# copy a design doc to another design doc
design_copy(x, dbname = "omdb", design = "view2", design_to = "view22")

## End(Not run)