forked from nicolai86/couchdb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.go
37 lines (32 loc) · 1006 Bytes
/
view.go
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
package couchdb
import (
"context"
"fmt"
)
// Results is a struct meant to be embedded in a couchdb request struct with correct
// rows, e.g.
//
// type UserResults struct {
// couchdb.Results
// Users []user `json:"rows"`
// }
type Results struct {
Offset int `json:"offset"`
TotalRows int `json:"total_rows"`
}
// View defines map & reduce functions for a single view
type View struct {
MapFn string `json:"map,omitempty"`
ReduceFn string `json:"reduce,omitempty"`
}
// DesignDocument describes a language and all associated views
type DesignDocument struct {
Document
Language string `json:"language"`
ValidateDocUpdate string `json:"validate_doc_update"`
Views map[string]View `json:"views"`
}
// Results executes a request against a couchdb view
func (d *Database) Results(ctx context.Context, design, view string, opts AllDocOpts, results interface{}) error {
return d.bulkGet(ctx, fmt.Sprintf("/_design/%s/_view/%s", design, view), opts, results)
}