Documentation ¶
Overview ¶
Package couch provides a CouchDB API.
Index ¶
- Variables
- type Change
- type ChangeHandler
- type ChangedRev
- type Changes
- type DBInfo
- type Database
- func (p Database) BaseURL() string
- func (p Database) Bulk(docs []interface{}) (results []Response, err error)
- func (p Database) Changes(handler ChangeHandler, options map[string]interface{}) error
- func (p Database) DBURL() string
- func (p Database) Delete(id, rev string) error
- func (p Database) DeleteDatabase() error
- func (p Database) Edit(d interface{}) (string, error)
- func (p Database) EditRetry(doc2update interface{}, updater RetryUpdater, doneMetric RetryDoneMetric, ...) (bool, error)
- func (p Database) EditWith(d interface{}, id, rev string) (string, error)
- func (p Database) Exists() bool
- func (p Database) GetChanges(options map[string]interface{}) (changes Changes, err error)
- func (p Database) GetInfo() (DBInfo, error)
- func (p Database) Insert(d interface{}) (string, string, error)
- func (p Database) InsertWith(d interface{}, id string) (string, string, error)
- func (p Database) LastSequence() (interface{}, error)
- func (p Database) Query(view string, options map[string]interface{}, results interface{}) error
- func (p Database) QueryIds(view string, options map[string]interface{}) ([]string, error)
- func (p Database) Retrieve(id string, d interface{}) error
- func (p Database) RetrieveAttachment(id string, name string) (io.Reader, error)
- func (p Database) Running() bool
- func (p Database) ViewURL(view string, params map[string]interface{}) (string, error)
- type DocID
- type Response
- type RetryDoneMetric
- type RetryRefresh
- type RetryUpdater
- type Row
Constants ¶
This section is empty.
Variables ¶
var HTTPClient *http.Client
HTTP Client used by typical requests.
Defaults to http.DefaultClient
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct { Sequence interface{} `json:"seq"` Id string `json:"id"` ChangedRevs []ChangedRev `json:"changes"` Deleted bool `json:"deleted"` }
type ChangeHandler ¶
A ChangeHandler handles the stream of changes coming from Changes.
The handler returns the next sequence number when the stream should be resumed, otherwise -1 to indicate the changes feed should stop.
The handler may return at any time to restart the stream from the sequence number in indicated in its return value.
type ChangedRev ¶
type ChangedRev struct {
Revision string `json:"rev"`
}
type Changes ¶
type Changes struct { Results []Change `json:"results"` LastSequence interface{} `json:"last_seq"` }
type DBInfo ¶
type DBInfo struct { Name string `json:"db_name"` DocCount int64 `json:"doc_count"` DocDelCount int64 `json:"doc_del_count"` UpdateSeq int64 `json:"update_seq"` PurgeSeq int64 `json:"purge_seq"` Compacting bool `json:"compact_running"` DiskSize int64 `json:"disk_size"` DataSize int64 `json:"data_size"` StartTime string `json:"instance_start_time"` Version int `json:"disk_format_version"` CommitedSeq int64 `json:"committed_update_seq"` }
DBInfo represents the result from GetInfo
type Database ¶
type Database struct { Scheme string Host string Port string Name string // contains filtered or unexported fields }
Database represents operations available on an existing CouchDB
func Connect ¶
Connect to the database at the given URL. example: couch.Connect("http://localhost:5984/testdb/")
func NewDatabase ¶
NewDatabase connects to a CouchDB server and creates the specified database if it does not exist.
func (Database) Bulk ¶
Bulk modification interface. Each item should be JSON serializable into a valid document. "_id" and "_rev" will be honored. To delete, add a "_deleted" field with a value of "true" as well as a valid "_rev" field.
func (Database) Changes ¶
func (p Database) Changes(handler ChangeHandler, options map[string]interface{}) error
Changes feeds a ChangeHandler a CouchDB changes feed.
The handler receives the body of the stream and is expected to consume the contents.
func (Database) DeleteDatabase ¶
DeleteDatabase deletes the given database and all documents
func (Database) Edit ¶
Edit edits the given document, returning the new revision. d must contain "_id" and "_rev" tagged fields.
func (Database) EditRetry ¶
func (p Database) EditRetry(doc2update interface{}, updater RetryUpdater, doneMetric RetryDoneMetric, refresh RetryRefresh) (bool, error)
Update with the ability to update/retry
The first return value will be true when it was updated due to calling this method, or false if it was already in that state or put in that state by something else during the update attempt.
If any errors occur while trying to update, they will be returned in the second return value.
func (Database) EditWith ¶
EditWith edits the given document, returning the new revision. d should not contain "_id" or "_rev" tagged fields. If it does, they will be overwritten with the passed values.
func (Database) GetChanges ¶
Simpler interface to Changes feed which returns a Changes struct
func (Database) Insert ¶
Insert a document into CouchDB, returning id and rev on success. Document may specify both "_id" and "_rev" fields (will overwrite existing)
or just "_id" (will use that id, but not overwrite existing) or neither (will use autogenerated id)
func (Database) InsertWith ¶
InsertWith inserts the given document (shouldn't contain "_id" or "_rev" tagged fields) using the passed 'id' as the _id. Will fail if the id already exists.
func (Database) LastSequence ¶
Reads the entire Changes feed to find the LastSequence
func (Database) QueryIds ¶
QueryIds returns a slice of document ids as returned by the given view/options combo. view should be eg. "_design/my_foo/_view/my_bar" options should be eg. { "limit": 10, "key": "baz" }
func (Database) RetrieveAttachment ¶
type RetryDoneMetric ¶
type RetryDoneMetric func() bool
type RetryRefresh ¶
type RetryRefresh func() error
type RetryUpdater ¶
type RetryUpdater func()