Documentation
¶
Overview ¶
Package couch provides a CouchDB API.
Index ¶
- Variables
- type Change
- type ChangeHandler
- type ChangedRev
- type Changes
- type CodedError
- 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) Compact() error
- func (p Database) DBURL() string
- func (p Database) Delete(id, rev string) error
- func (p Database) DeleteDatabase() error
- func (p Database) DeleteRole(name string) error
- func (p Database) DeleteUser(name string) error
- func (p Database) Edit(d interface{}) (string, error)
- func (p Database) EditWith(d interface{}, id, rev string) (string, error)
- func (p Database) Exists() bool
- 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) IsAdmin() bool
- 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) Role(name string) (Role, error)
- func (p Database) Running() bool
- func (p Database) Session(name string, ttl uint) (http.Cookie, error)
- func (p Database) SetRole(role Role) error
- func (p Database) SetUser(user User) error
- func (p Database) StartProfile(file string) error
- func (p Database) StopProfile() error
- func (p Database) User(name string) (User, error)
- func (p Database) ViewURL(view string, params map[string]interface{}) (string, error)
- type DocID
- type Response
- type Role
- type Row
- type User
Constants ¶
This section is empty.
Variables ¶
var HTTPClient = http.DefaultClient
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 CodedError ¶
type CodedError struct {
Code int
// contains filtered or unexported fields
}
func (*CodedError) Error ¶
func (e *CodedError) Error() string
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 {
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) DeleteRole ¶
func (Database) DeleteUser ¶
func (Database) Edit ¶
Edit edits the given document, returning the new revision. d must contain "_id" and "_rev" tagged fields.
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) 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) StartProfile ¶
func (Database) StopProfile ¶
type User ¶
type User struct {
Name string `json:"name,omitempty"`
Password string `json:"password,omitempty"`
Email []string `json:"email,omitempty"`
AdminChannels []string `json:"admin_channels,omitempty"`
AdminRoles []string `json:"admin_roles,omitempty"`
AllChannels []string `json:"all_channels,omitempty"`
Roles []string `json:"roles,omitempty"`
Disabled bool `json:"disabled,omitempty"`
}
