design: Work with design documents

Description Usage Arguments Details Value Examples

Description

Work with design documents

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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, ...)

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 HttpClient

fxn

(character) a javascript function. required for view_put_

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
## 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 <- design_search(x, dbname='omdb', design='view2')
head(
  do.call(
    "rbind.data.frame",
    lapply(res$rows, function(x) Filter(length, x))
  )
)

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

## End(Not run)

sofa documentation built on Jan. 4, 2018, 3:43 a.m.