Documentation ¶
Overview ¶
Package couchdb provides components to work with CouchDB 2.x with Go.
Resource is the low-level wrapper functions of HTTP methods used for communicating with CouchDB Server.
Server contains all the functions to work with CouchDB server, including some basic functions to facilitate the basic user management provided by it.
Database contains all the functions to work with CouchDB database, such as documents manipulating and querying.
ViewResults represents the results produced by design document views. When calling any of its functions like Offset(), TotalRows(), UpdateSeq() or Rows(), it will perform a query on views on server side, and returns results as slice of Row
ViewDefinition is a definition of view stored in a specific design document, you can define your own map-reduce functions and Sync with the database.
Document represents a document object in database. All struct that can be mapped into CouchDB document must have it embedded. For example:
type User struct { Name string `json:"name"` Age int `json:"age"` Document } user := User{"Mike", 18} anotherUser := User{}
Then you can call Store(db, &user) to store it into CouchDB or Load(db, user.GetID(), &anotherUser) to get the data from database.
ViewField represents a view definition value bound to Document.
tools/replicate is a command-line tool for replicating databases from one CouchDB server to another. This is mainly for backup purposes, but you can also use -continuous option to set up automatic replication.
Index ¶
- Constants
- Variables
- func FromJSONCompatibleMap(obj interface{}, docMap map[string]interface{}) error
- func GenerateUUID() string
- func Load(ctx context.Context, db *Database, docID string, obj interface{}) error
- func Store(ctx context.Context, db *Database, obj interface{}) error
- func ToJSONCompatibleMap(obj interface{}) (map[string]interface{}, error)
- type Database
- func (d *Database) Available(ctx context.Context) error
- func (d *Database) Changes(ctx context.Context, options url.Values) (map[string]interface{}, error)
- func (d *Database) Cleanup(ctx context.Context) error
- func (d *Database) Commit(ctx context.Context) error
- func (d *Database) Compact(ctx context.Context) error
- func (d *Database) Contains(ctx context.Context, docid string) error
- func (d *Database) Copy(ctx context.Context, srcID, destID, destRev string) (string, error)
- func (d *Database) Delete(ctx context.Context, docid string) error
- func (d *Database) DeleteAttachment(ctx context.Context, doc map[string]interface{}, name string) error
- func (d *Database) DeleteDoc(ctx context.Context, doc map[string]interface{}) error
- func (d *Database) DeleteIndex(ctx context.Context, ddoc, name string) error
- func (d *Database) DocIDs(ctx context.Context) ([]string, error)
- func (d *Database) Get(ctx context.Context, docid string, options url.Values) (map[string]interface{}, error)
- func (d *Database) GetAttachment(ctx context.Context, doc map[string]interface{}, name string) ([]byte, error)
- func (d *Database) GetAttachmentID(ctx context.Context, docid, name string) ([]byte, error)
- func (d *Database) GetIndex(ctx context.Context) (map[string]*json.RawMessage, error)
- func (d *Database) GetRevsLimit(ctx context.Context) (int, error)
- func (d *Database) GetSecurity(ctx context.Context) (map[string]interface{}, error)
- func (d *Database) Info(ctx context.Context, ddoc string) (map[string]interface{}, error)
- func (d *Database) IterView(ctx context.Context, name string, batch int, wrapper func(Row) Row, ...) (<-chan IterViewResult, error)
- func (d *Database) Len(ctx context.Context) (int, error)
- func (d *Database) List(ctx context.Context, name, view string, options map[string]interface{}) (http.Header, []byte, error)
- func (d *Database) Name(ctx context.Context) (string, error)
- func (d *Database) Purge(ctx context.Context, docs []map[string]interface{}) (map[string]interface{}, error)
- func (d *Database) PutAttachment(ctx context.Context, doc map[string]interface{}, content []byte, ...) error
- func (d *Database) PutIndex(ctx context.Context, indexFields []string, ddoc, name string) (string, string, error)
- func (d *Database) Query(ctx context.Context, fields []string, selector string, sorts []string, ...) ([]map[string]interface{}, error)
- func (d *Database) QueryJSON(ctx context.Context, query string) ([]map[string]interface{}, error)
- func (d *Database) Revisions(ctx context.Context, docid string, options url.Values) ([]map[string]interface{}, error)
- func (d *Database) Save(ctx context.Context, doc map[string]interface{}, options url.Values) (string, string, error)
- func (d *Database) Set(ctx context.Context, docid string, doc map[string]interface{}) error
- func (d *Database) SetRevsLimit(ctx context.Context, limit int) error
- func (d *Database) SetSecurity(ctx context.Context, securityDoc map[string]interface{}) error
- func (d *Database) Show(ctx context.Context, name, docID string, params url.Values) (http.Header, []byte, error)
- func (d *Database) String() string
- func (d *Database) Update(ctx context.Context, docs []map[string]interface{}, ...) ([]UpdateResult, error)
- func (d *Database) UpdateDoc(ctx context.Context, name, docID string, params url.Values) (http.Header, []byte, error)
- func (d *Database) View(name string, wrapper func(Row) Row, options map[string]interface{}) IViewResults
- type DatabaseInfo
- type Document
- type IDatabase
- type IServer
- type IViewResults
- type IterViewResult
- type Resource
- func (r *Resource) Delete(ctx context.Context, path string, header http.Header, params url.Values) (http.Header, []byte, error)
- func (r *Resource) DeleteJSON(ctx context.Context, path string, header http.Header, params url.Values) (http.Header, []byte, error)
- func (r *Resource) Get(ctx context.Context, path string, header http.Header, params url.Values) (http.Header, []byte, error)
- func (r *Resource) GetJSON(ctx context.Context, path string, header http.Header, params url.Values) (http.Header, []byte, error)
- func (r *Resource) Head(ctx context.Context, path string, header http.Header, params url.Values) (http.Header, []byte, error)
- func (r *Resource) NewResourceWithURL(resStr string) (*Resource, error)
- func (r *Resource) Post(ctx context.Context, path string, header http.Header, body []byte, ...) (http.Header, []byte, error)
- func (r *Resource) PostJSON(ctx context.Context, path string, header http.Header, ...) (http.Header, []byte, error)
- func (r *Resource) Put(ctx context.Context, path string, header http.Header, body []byte, ...) (http.Header, []byte, error)
- func (r *Resource) PutJSON(ctx context.Context, path string, header http.Header, ...) (http.Header, []byte, error)
- type Row
- type Server
- func (s *Server) ActiveTasks(ctx context.Context) ([]interface{}, error)
- func (s *Server) AddUser(ctx context.Context, name, password string, roles []string) (string, string, error)
- func (s *Server) Config(ctx context.Context, node string) (map[string]map[string]string, error)
- func (s *Server) Contains(ctx context.Context, name string) bool
- func (s *Server) Create(ctx context.Context, name string) (*Database, error)
- func (s *Server) DBs(ctx context.Context) ([]string, error)
- func (s *Server) DBsWithParams(ctx context.Context, headers http.Header, params url.Values) ([]string, error)
- func (s *Server) Delete(ctx context.Context, name string) error
- func (s *Server) Get(ctx context.Context, name string) (*Database, error)
- func (s *Server) GetDatabaseInfo(ctx context.Context, name string) (*DatabaseInfo, error)
- func (s *Server) Len(ctx context.Context) (int, error)
- func (s *Server) Login(ctx context.Context, name, password string) (string, error)
- func (s *Server) Logout(ctx context.Context, token string) error
- func (s *Server) Membership(ctx context.Context) ([]string, []string, error)
- func (s *Server) RemoveUser(ctx context.Context, name string) error
- func (s *Server) Replicate(ctx context.Context, source, target string, options map[string]interface{}) (map[string]interface{}, error)
- func (s *Server) Stats(ctx context.Context, node, entry string) (map[string]interface{}, error)
- func (s *Server) String() string
- func (s *Server) UUIDs(ctx context.Context, count int) ([]string, error)
- func (s *Server) VerifyToken(ctx context.Context, token string) error
- func (s *Server) Version(ctx context.Context) (string, error)
- type UpdateResult
- type ViewDefinition
- type ViewField
- type ViewResults
Constants ¶
const (
// DefaultBaseURL is the default address of CouchDB server.
DefaultBaseURL = "http://localhost:5984"
)
Variables ¶
var ( // ErrBatchValue for invalid batch parameter of IterView ErrBatchValue = errors.New("batch must be 1 or more") // ErrLimitValue for invalid limit parameter of IterView ErrLimitValue = errors.New("limit must be 1 or more") )
var ( // ErrSetID for setting ID to document which already has one. ErrSetID = errors.New("id can only be set on new documents") // ErrNotStruct for not a struct value ErrNotStruct = errors.New("value not of struct type") // ErrNotDocumentEmbedded for not a document-embedded value ErrNotDocumentEmbedded = errors.New("value not Document-embedded") )
var ( // ErrNotModified for HTTP status code 304 ErrNotModified = errors.New("status 304 - not modified") // ErrBadRequest for HTTP status code 400 ErrBadRequest = errors.New("status 400 - bad request") ErrUnauthorized = errors.New("status 401 - unauthorized") // ErrForbidden for HTTP status code 403 ErrForbidden = errors.New("status 403 - forbidden") // ErrNotFound for HTTP status code 404 ErrNotFound = errors.New("status 404 - not found") // ErrResourceNotAllowed for HTTP status code 405 ErrResourceNotAllowed = errors.New("status 405 - resource not allowed") // ErrNotAcceptable for HTTP status code 406 ErrNotAcceptable = errors.New("status 406 - not acceptable") // ErrConflict for HTTP status code 409 ErrConflict = errors.New("status 409 - conflict") // ErrPreconditionFailed for HTTP status code 412 ErrPreconditionFailed = errors.New("status 412 - precondition failed") // ErrBadContentType for HTTP status code 415 ErrBadContentType = errors.New("status 415 - bad content type") // ErrRequestRangeNotSatisfiable for HTTP status code 416 ErrRequestRangeNotSatisfiable = errors.New("status 416 - requested range not satisfiable") // ErrExpectationFailed for HTTP status code 417 ErrExpectationFailed = errors.New("status 417 - expectation failed") // ErrInternalServerError for HTTP status code 500 ErrInternalServerError = errors.New("status 500 - internal server error") )
Functions ¶
func FromJSONCompatibleMap ¶
FromJSONCompatibleMap constructs a Document-embedded struct from a JSON-compatible map.
func Store ¶
Store stores the document in specified database. obj: a Document-embedded struct value, its id and rev will be updated after stored, so caller must pass a pointer value.
func ToJSONCompatibleMap ¶
ToJSONCompatibleMap converts a Document-embedded struct into a JSON-compatible map, e.g. anything that cannot be jsonified will be ignored silently.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database represents a CouchDB database instance.
func NewDatabase ¶
NewDatabase returns a CouchDB database instance.
func NewDatabaseWithResource ¶
NewDatabaseWithResource returns a CouchDB database instance with resource obj.
func (*Database) Changes ¶
Changes returns a sorted list of changes feed made to documents in the database.
func (*Database) Commit ¶
Commit flushes any recent changes to the specified database to disk. If the server is configured to delay commits or previous requests use the special "X-Couch-Full-Commit: false" header to disable immediate commits, this method can be used to ensure that non-commited changes are commited to physical storage.
func (*Database) Contains ¶
Contains returns true if the database contains a document with the specified ID.
func (*Database) DeleteAttachment ¶
func (d *Database) DeleteAttachment(ctx context.Context, doc map[string]interface{}, name string) error
DeleteAttachment deletes the specified attachment
func (*Database) DeleteIndex ¶
DeleteIndex deletes index in database.
func (*Database) Get ¶
func (d *Database) Get(ctx context.Context, docid string, options url.Values) (map[string]interface{}, error)
Get returns the document with the specified ID.
func (*Database) GetAttachment ¶
func (d *Database) GetAttachment(ctx context.Context, doc map[string]interface{}, name string) ([]byte, error)
GetAttachment returns the file attachment associated with the document. The raw data is returned as a []byte.
func (*Database) GetAttachmentID ¶
GetAttachmentID returns the file attachment associated with the document ID. The raw data is returned as []byte.
func (*Database) GetRevsLimit ¶
GetRevsLimit gets the current revs_limit(revision limit) setting.
func (*Database) GetSecurity ¶
GetSecurity returns the current security object from the given database.
func (*Database) IterView ¶
func (d *Database) IterView(ctx context.Context, name string, batch int, wrapper func(Row) Row, opts map[string]interface{}) (<-chan IterViewResult, error)
IterView returns a channel fetching rows in batches which iterates a row at a time(pagination).
name: the name of the view, for user-defined views use the format "design_docid/viewname", that is, the document ID of the design document and the name of the view, separated by a /.
wrapper: an optional function for processing the result rows after retrieved.
options: optional query parameters.
func (*Database) List ¶
func (d *Database) List(ctx context.Context, name, view string, options map[string]interface{}) (http.Header, []byte, error)
List formats a view using a server-side 'list' function.
name: the name of the list function in the format "designdoc/listname"
view: the name of the view in the format "designdoc/viewname"
options: optional query parameters
func (*Database) Purge ¶
func (d *Database) Purge(ctx context.Context, docs []map[string]interface{}) (map[string]interface{}, error)
Purge performs complete removing of the given documents.
func (*Database) PutAttachment ¶
func (d *Database) PutAttachment(ctx context.Context, doc map[string]interface{}, content []byte, name, mimeType string) error
PutAttachment uploads the supplied []byte as an attachment to the specified document. doc: the document that the attachment belongs to. Must have _id and _rev inside. content: the data to be attached to doc. name: name of attachment. mimeType: MIME type of content.
func (*Database) PutIndex ¶
func (d *Database) PutIndex(ctx context.Context, indexFields []string, ddoc, name string) (string, string, error)
PutIndex creates a new index in database.
indexFields: a JSON array of field names following the sort syntax.
ddoc: optional, name of the design document in which the index will be created. By default each index will be created in its own design document. Indexes can be grouped into design documents for efficiency. However a change to one index in a design document will invalidate all other indexes in the same document.
name: optional, name of the index. A name generated automatically if not provided.
func (*Database) Query ¶
func (d *Database) Query(ctx context.Context, fields []string, selector string, sorts []string, limit, skip, index interface{}) ([]map[string]interface{}, error)
Query returns documents using a conditional selector statement in Golang.
selector: A filter string declaring which documents to return, formatted as a Golang statement.
fields: Specifying which fields to be returned, if passing nil the entire is returned, no automatic inclusion of _id or other metadata fields.
sorts: How to order the documents returned, formatted as ["desc(fieldName1)", "desc(fieldName2)"] or ["fieldNameA", "fieldNameB"] of which "asc" is used by default, passing nil to disable ordering.
limit: Maximum number of results returned, passing nil to use default value(25).
skip: Skip the first 'n' results, where 'n' is the number specified, passing nil for no-skip.
index: Instruct a query to use a specific index, specified either as "<design_document>" or ["<design_document>", "<index_name>"], passing nil to use primary index(_all_docs) by default.
Inner functions for selector syntax ¶
nor(condexprs...) matches if none of the conditions in condexprs match($nor).
For example: nor(year == 1990, year == 1989, year == 1997) returns all documents whose year field not in 1989, 1990 and 1997.
all(field, array) matches an array value if it contains all the elements of the argument array($all).
For example: all(genre, []string{"Comedy", "Short"} returns all documents whose genre field contains "Comedy" and "Short".
any(field, condexpr) matches an array field with at least one element meets the specified condition($elemMatch).
For example: any(genre, genre == "Short" || genre == "Horror") returns all documents whose genre field contains "Short" or "Horror" or both.
exists(field, boolean) checks whether the field exists or not, regardless of its value($exists).
For example: exists(director, false) returns all documents who does not have a director field.
typeof(field, type) checks the document field's type, valid types are "null", "boolean", "number", "string", "array", "object"($type).
For example: typeof(genre, "array") returns all documents whose genre field is of array type.
in(field, array) the field must exist in the array provided($in).
For example: in(director, []string{"Mike Portnoy", "Vitali Kanevsky"}) returns all documents whose director field is "Mike Portnoy" or "Vitali Kanevsky".
nin(field, array) the document field must not exist in the array provided($nin).
For example: nin(year, []int{1990, 1992, 1998}) returns all documents whose year field is not in 1990, 1992 or 1998.
size(field, int) matches the length of an array field in a document($size).
For example: size(genre, 2) returns all documents whose genre field is of length 2.
mod(field, divisor, remainder) matches documents where field % divisor == remainder($mod).
For example: mod(year, 2, 1) returns all documents whose year field is an odd number.
regex(field, regexstr) a regular expression pattern to match against the document field.
For example: regex(title, "^A") returns all documents whose title is begin with an "A".
Inner functions for sort syntax ¶
asc(field) sorts the field in ascending order, this is the default option while desc(field) sorts the field in descending order.
func (*Database) Revisions ¶
func (d *Database) Revisions(ctx context.Context, docid string, options url.Values) ([]map[string]interface{}, error)
Revisions returns all available revisions of the given document in reverse order, e.g. latest first.
func (*Database) Save ¶
func (d *Database) Save(ctx context.Context, doc map[string]interface{}, options url.Values) (string, string, error)
Save creates a new document or update an existing document. If doc has no _id the server will generate a random UUID and a new document will be created. Otherwise the doc's _id will be used to identify the document to create or update. Trying to update an existing document with an incorrect _rev will cause failure. *NOTE* It is recommended to avoid saving doc without _id and instead generate document ID on client side. To avoid such problems you can generate a UUID on the client side. GenerateUUID provides a simple, platform-independent implementation. You can also use other third-party packages instead. doc: the document to create or update.
func (*Database) SetRevsLimit ¶
SetRevsLimit sets the maximum number of document revisions that will be tracked by CouchDB.
func (*Database) SetSecurity ¶
SetSecurity sets the security object for the given database.
func (*Database) Show ¶
func (d *Database) Show(ctx context.Context, name, docID string, params url.Values) (http.Header, []byte, error)
Show calls a server-side 'show' function.
name: the name of the show function in the format "designdoc/showname"
docID: optional document ID to pass to the show function
params: optional query parameters
func (*Database) Update ¶
func (d *Database) Update(ctx context.Context, docs []map[string]interface{}, options map[string]interface{}) ([]UpdateResult, error)
Update performs a bulk update or creation of the given documents in a single HTTP request. It returns a 3-tuple (id, rev, error)
func (*Database) UpdateDoc ¶
func (d *Database) UpdateDoc(ctx context.Context, name, docID string, params url.Values) (http.Header, []byte, error)
UpdateDoc calls server-side update handler.
name: the name of the update handler function in the format "designdoc/updatename".
docID: optional document ID to pass to the show function
params: optional query parameters
func (*Database) View ¶
func (d *Database) View(name string, wrapper func(Row) Row, options map[string]interface{}) IViewResults
View executes a predefined design document view and returns the results.
name: the name of the view, for user-defined views use the format "design_docid/viewname", that is, the document ID of the design document and the name of the view, separated by a /.
wrapper: an optional function for processing the result rows after retrieved.
options: optional query parameters.
type DatabaseInfo ¶ added in v1.2.2
type DatabaseInfo struct { DbName string `json:"db_name"` PurgeSeq string `json:"purge_seq"` UpdateSeq string `json:"update_seq"` Sizes struct { File int `json:"file"` External int `json:"external"` Active int `json:"active"` } `json:"sizes"` Other struct { DataSize int `json:"data_size"` } `json:"other"` DocDelCount int `json:"doc_del_count"` DocCount int `json:"doc_count"` DiskSize int `json:"disk_size"` DiskFormatVersion int `json:"disk_format_version"` DataSize int `json:"data_size"` CompactRunning bool `json:"compact_running"` Cluster struct { Q int `json:"q"` N int `json:"n"` W int `json:"w"` R int `json:"r"` } `json:"cluster"` InstanceStartTime string `json:"instance_start_time"` }
type Document ¶
type Document struct { ID string `json:"_id,omitempty"` // for json only, call SetID/GetID instead Rev string `json:"_rev,omitempty"` // for json only, call GetRev instead // contains filtered or unexported fields }
Document represents a document object in database.
func DocumentWithID ¶
DocumentWithID returns a new Document with ID.
type IViewResults ¶ added in v1.2.3
type IterViewResult ¶ added in v1.2.7
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource handles all requests to CouchDB
func NewResource ¶
NewResource returns a newly-created Resource instance
func NewResourceWithClient ¶ added in v1.2.4
func NewResourceWithClient(urlStr string, header http.Header, client *http.Client) (*Resource, error)
NewResourceWithClient returns a newly-created Resource instance with a received http client
func (*Resource) Delete ¶
func (r *Resource) Delete(ctx context.Context, path string, header http.Header, params url.Values) (http.Header, []byte, error)
Delete is a wrapper around http.Delete
func (*Resource) DeleteJSON ¶
func (r *Resource) DeleteJSON(ctx context.Context, path string, header http.Header, params url.Values) (http.Header, []byte, error)
DeleteJSON issues a DELETE to the specified URL, with data returned as json
func (*Resource) Get ¶
func (r *Resource) Get(ctx context.Context, path string, header http.Header, params url.Values) (http.Header, []byte, error)
Get is a wrapper around http.Get
func (*Resource) GetJSON ¶
func (r *Resource) GetJSON(ctx context.Context, path string, header http.Header, params url.Values) (http.Header, []byte, error)
GetJSON issues a GET to the specified URL, with data returned as json
func (*Resource) Head ¶
func (r *Resource) Head(ctx context.Context, path string, header http.Header, params url.Values) (http.Header, []byte, error)
Head is a wrapper around http.Head
func (*Resource) NewResourceWithURL ¶
NewResourceWithURL returns newly created *Resource combined with resource string.
func (*Resource) Post ¶
func (r *Resource) Post(ctx context.Context, path string, header http.Header, body []byte, params url.Values) (http.Header, []byte, error)
Post is a wrapper around http.Post
func (*Resource) PostJSON ¶
func (r *Resource) PostJSON(ctx context.Context, path string, header http.Header, body map[string]interface{}, params url.Values) (http.Header, []byte, error)
PostJSON issues a POST to the specified URL, with data returned as json
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents a CouchDB server instance.
func NewServerNoFullCommit ¶
NewServerNoFullCommit creates a CouchDB server instance in address urlStr with X-Couch-Full-Commit disabled.
func NewServerWithClient ¶ added in v1.2.4
NewServerWithClient creates a CouchDB server instance in address urlStr and including configuration for prometheus metrics
func (*Server) ActiveTasks ¶
ActiveTasks lists of running tasks.
func (*Server) AddUser ¶
func (s *Server) AddUser(ctx context.Context, name, password string, roles []string) (string, string, error)
AddUser adds regular user in authentication database. Returns id and rev of the registered user.
func (*Server) Create ¶
Create returns a database instance with the given name, returns true if created, if database already existed, returns false, *Database will be nil if failed.
func (*Server) DBsWithParams ¶ added in v1.2.3
func (s *Server) DBsWithParams(ctx context.Context, headers http.Header, params url.Values) ([]string, error)
DBsWithParams returns a list of all the databases in the CouchDB server instance, supporting headers and params
func (*Server) GetDatabaseInfo ¶ added in v1.2.2
GetDatabaseInfo retrieve information about the database
func (*Server) Membership ¶
Membership displays the nodes that are part of the cluster as clusterNodes. The field allNodes displays all nodes this node knows about, including the ones that are part of cluster.
func (*Server) RemoveUser ¶
RemoveUser removes regular user in authentication database.
func (*Server) Replicate ¶
func (s *Server) Replicate(ctx context.Context, source, target string, options map[string]interface{}) (map[string]interface{}, error)
Replicate requests, configure or stop a replication operation.
func (*Server) Stats ¶
Stats returns a JSON object containing the statistics for the running server.
func (*Server) UUIDs ¶
UUIDs requests one or more Universally Unique Identifiers from the CouchDB instance. The response is a JSON object providing a list of UUIDs. count - Number of UUIDs to return. Default is 1.
func (*Server) VerifyToken ¶
VerifyToken returns error if user's token is invalid.
type UpdateResult ¶
UpdateResult represents result of an update.
func SyncMany ¶
func SyncMany(ctx context.Context, db *Database, viewDefns []*ViewDefinition, removeMissing bool, callback func(map[string]interface{})) ([]UpdateResult, error)
SyncMany ensures that the views stored in the database match the views defined by the corresponding view definitions. This function might update more than one design document. This is done using CouchDB's bulk update to ensure atomicity of the opeation. db: the corresponding database.
viewDefns: a sequence of *ViewDefinition instances.
removeMissing: whether to remove views found in a design document that are not found in the list of ViewDefinition instances, default false.
callback: a callback function invoked when a design document gets updated; it is called before the doc has actually been saved back to the database.
type ViewDefinition ¶
type ViewDefinition struct {
// contains filtered or unexported fields
}
ViewDefinition is a definition of view stored in a specific design document.
func NewViewDefinition ¶
func NewViewDefinition(design, name, mapFun, reduceFun, language string, wrapper func(Row) Row, options map[string]interface{}) (*ViewDefinition, error)
NewViewDefinition returns a newly-created *ViewDefinition. design: the name of the design document.
name: the name of the view.
mapFun: the map function code.
reduceFun: the reduce function code(optional).
language: the name of the programming language used, default is javascript.
wrapper: an optional function for processing the result rows after retrieved.
options: view specific options.
func (*ViewDefinition) GetDoc ¶
GetDoc retrieves the design document corresponding to this view definition from the given database.
func (*ViewDefinition) Sync ¶
func (vd *ViewDefinition) Sync(ctx context.Context, db *Database) ([]UpdateResult, error)
Sync ensures that the view stored in the database matches the view defined by this instance.
func (*ViewDefinition) View ¶
func (vd *ViewDefinition) View(db *Database, options map[string]interface{}) IViewResults
View executes the view definition in the given database.
type ViewField ¶
type ViewField func() (*ViewDefinition, error)
ViewField represents a view definition value bound to Document.
func NewViewField ¶
func NewViewField(design, name, mapFun, reduceFun, language string, wrapper func(Row) Row, options map[string]interface{}) ViewField
NewViewField returns a ViewField function. design: the name of the design document.
name: the name of the view.
mapFun: the map function code.
reduceFun: the reduce function code(optional).
language: the name of the programming language used, default is javascript.
wrapper: an optional function for processing the result rows after retrieved.
options: view specific options.
type ViewResults ¶
type ViewResults struct {
// contains filtered or unexported fields
}
ViewResults represents the results produced by design document views.
func (*ViewResults) Offset ¶
func (vr *ViewResults) Offset(ctx context.Context) (int, error)
Offset returns offset of ViewResults
func (*ViewResults) Rows ¶
func (vr *ViewResults) Rows(ctx context.Context) ([]Row, error)
Rows returns a slice of rows mapped (and reduced) by the view.