Documentation ¶
Overview ¶
Package gocouch implements wrappers for the 95% of CouchDB HTTP API
Index ¶
- type Attachment
- type AttachmentInfo
- type Auth
- type BasicAuth
- type DBInfo
- type Database
- func (db *Database) AttachmentInfo(id, name string) (*AttachmentInfo, error)
- func (db *Database) Compact() error
- func (db *Database) CompactDesign(docName string) error
- func (db *Database) Copy(id string, dest Destination, options Options) (string, error)
- func (db *Database) Del(id, rev string) (string, error)
- func (db *Database) DelAttachment(id, name, rev string) error
- func (db *Database) Delete() error
- func (db *Database) DeleteMany(docs interface{}) ([]UpdateResult, error)
- func (db *Database) EnsureFullCommit() error
- func (db *Database) Exists(id string, options Options) (size int, rev string, err error)
- func (db *Database) Get(id string, o interface{}, options Options) error
- func (db *Database) GetAllChanges(options Options) (*DatabaseChanges, error)
- func (db *Database) GetAllDocs(options Options) (*ViewResult, error)
- func (db *Database) GetAllDocsByIDs(keys []string, options Options) (*ViewResult, error)
- func (db *Database) GetAttachment(id, name, rev string) (*Attachment, error)
- func (db *Database) GetChangesChan(options Options) (c chan DatabaseEvent, err error)
- func (db *Database) GetDatabaseSecurity() *DatabaseSecurity
- func (db *Database) GetMissedRevs(o map[string][]string) (map[string]map[string][]string, error)
- func (db *Database) GetRevsDiff(o map[string][]string) (map[string]map[string][]string, error)
- func (db *Database) GetRevsLimit() (count int, err error)
- func (db *Database) GetSecurity(o SecurityObject) error
- func (db *Database) GetTempView(_map, reduce string) (*ViewResult, error)
- func (db *Database) Info() (*DBInfo, error)
- func (db *Database) Insert(doc interface{}, batch, fullCommit bool) (id, rev string, err error)
- func (db *Database) InsertMany(docs interface{}) ([]UpdateResult, error)
- func (db *Database) MustDeleteMany(docs interface{}) ([]UpdateResult, error)
- func (db *Database) MustInsertMany(docs interface{}) ([]UpdateResult, error)
- func (db *Database) Purge(o map[string][]string) (*PurgeResult, error)
- func (db *Database) Put(id string, doc interface{}) (string, error)
- func (db *Database) SaveAttachment(id, rev string, a *Attachment) (map[string]interface{}, error)
- func (db *Database) SetRevsLimit(count int) error
- func (db *Database) SetSecurity(o SecurityObject) error
- func (db *Database) Update(docs interface{}, atomic, updateRev, fullCommit bool) ([]UpdateResult, error)
- func (db *Database) ViewCleanup() error
- type DatabaseChanges
- type DatabaseEvent
- type DatabaseSecurity
- func (sec *DatabaseSecurity) AddAdmin(login string) error
- func (sec *DatabaseSecurity) AddAdminRole(role string) error
- func (sec *DatabaseSecurity) AddMember(login string) error
- func (sec *DatabaseSecurity) AddMemberRole(role string) error
- func (sec *DatabaseSecurity) DeleteAdmin(login string) error
- func (sec *DatabaseSecurity) DeleteAdminRole(role string) error
- func (sec *DatabaseSecurity) DeleteMember(login string) error
- func (sec *DatabaseSecurity) DeleteMemberRole(role string) error
- type DefaultSecurity
- func (bs *DefaultSecurity) UpdateAdminRoles(login string, delete bool) error
- func (bs *DefaultSecurity) UpdateAdmins(login string, delete bool) error
- func (bs *DefaultSecurity) UpdateMemberRoles(login string, delete bool) error
- func (bs *DefaultSecurity) UpdateMembers(login string, delete bool) error
- type Destination
- type Error
- type Options
- type PurgeResult
- type ReplicationResult
- type SecurityGroup
- type SecurityObject
- type Server
- func (srv *Server) Copy() (*Server, error)
- func (srv *Server) CreateDB(name string) (*Database, error)
- func (srv *Server) CreateUser(user *UserRecord) error
- func (srv *Server) GetActiveTasks(o interface{}) error
- func (srv *Server) GetAllDBs() (dbList []string, err error)
- func (srv *Server) GetDBEvent(o interface{}, options Options) error
- func (srv *Server) GetDBEventChan() (c chan ServerEvent, err error)
- func (srv *Server) GetDatabase(name string, auth Auth) (*Database, error)
- func (srv *Server) GetLog(size int) (*bytes.Buffer, error)
- func (srv *Server) GetMembership(o interface{}) error
- func (srv *Server) GetUUIDs(count int) ([]string, error)
- func (srv *Server) Info() (*ServerInfo, error)
- func (srv *Server) MustGetDatabase(name string, auth Auth) (*Database, error)
- func (srv *Server) NewSession(user, pass string) (*Session, error)
- func (srv *Server) Replicate(source, target string, options Options) (*ReplicationResult, error)
- func (srv *Server) Restart() error
- func (srv *Server) Stats(path []string, o interface{}) error
- type ServerEvent
- type ServerInfo
- type Session
- type UpdateResult
- type UserRecord
- type ViewResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
Attachment represents attachment to be stored in couchdb
type AttachmentInfo ¶
AttachmentInfo provides information about attachment
type BasicAuth ¶
type BasicAuth struct {
Username, Password string
}
BasicAuth provides simple user:password authentication
func (BasicAuth) AddAuthHeaders ¶
AddAuthHeaders used to add authentication headers to the request
type DBInfo ¶
type DBInfo struct { CommitedUpdateSeq int `json:"committed_update_seq"` CompactRunning bool `json:"compact_running"` Name string `json:"db_name"` DiskVersion int `json:"disk_format_version"` DataSize int `json:"data_size"` DiskSize int `json:"disk_size"` DocCount int `json:"doc_count"` DocDelCount int `json:"doc_del_count"` StartTime string `json:"instance_start_time"` PurgeSeq int `json:"purge_seq"` UpdateSeq int `json:"update_seq"` }
DBInfo describes a database information
type Database ¶
type Database struct { Name string // contains filtered or unexported fields }
Database contains connection to couchdb instance and db name auth is inherited from Server on creation, but you can change it anytime
func (*Database) AttachmentInfo ¶
func (db *Database) AttachmentInfo(id, name string) (*AttachmentInfo, error)
AttachementInfo provides basic information about specified attachment
func (*Database) CompactDesign ¶
CompactDesign copacts the view indexes associated with specified design document
func (*Database) Copy ¶
Copy... copies docuement with specified id to newly created document, ot to existing one. Note: if you're copying document to the existing one, you must specify target latest revision, otherwise couchdb will return 409(Conflict)
func (*Database) DelAttachment ¶
DelAttachment used for deleting document's attachments
func (*Database) DeleteMany ¶
func (db *Database) DeleteMany(docs interface{}) ([]UpdateResult, error)
DeleteMany is a shortcut to delete method. Use it when you have documents you want to delete from database.
Argument may be `[]interface{}` or `[]map[string]string`
If you pass a slice of struct note that they must have fields with tags "_id" and "_rev", or error will be returned For maps here is a similar requirement, they must have both "_id" and "_rev" keys
func (*Database) EnsureFullCommit ¶
EnsureFullCommit tells database to commit any recent changes to the specified database to disk
func (*Database) GetAllChanges ¶
func (db *Database) GetAllChanges(options Options) (*DatabaseChanges, error)
GetAllChanges fetches all changes for current database
func (*Database) GetAllDocs ¶
func (db *Database) GetAllDocs(options Options) (*ViewResult, error)
GetAllDocs function returns pointer to ViewResult
func (*Database) GetAllDocsByIDs ¶
func (db *Database) GetAllDocsByIDs(keys []string, options Options) (*ViewResult, error)
GetAllDocsByIDs does same as GetAllDocs but in defferent way
func (*Database) GetAttachment ¶
func (db *Database) GetAttachment(id, name, rev string) (*Attachment, error)
GetAttachment fetches attachement from database
func (*Database) GetChangesChan ¶
func (db *Database) GetChangesChan(options Options) (c chan DatabaseEvent, err error)
GetChangesChan returns a channel from which a DatabaseEvents can be obtained
func (*Database) GetDatabaseSecurity ¶
func (db *Database) GetDatabaseSecurity() *DatabaseSecurity
GetDatabaseSecurity returns security object of current database
func (*Database) GetMissedRevs ¶
GetMissedRevs with a given list of revisions returns ones that do not exists in the database. List example:
check_revs := map[string][]string{"document_id": []string{"rev1", "rev2"}}
func (*Database) GetRevsDiff ¶
GetRevsDiff returns the subset of those revs that do not correspond to stored in the database
func (*Database) GetRevsLimit ¶
GetRevsLimit gets the current database revision limit
func (*Database) GetSecurity ¶
func (db *Database) GetSecurity(o SecurityObject) error
GetSecurity fetches database security object
func (*Database) GetTempView ¶
func (db *Database) GetTempView(_map, reduce string) (*ViewResult, error)
GetTempView return a pointer to ViewResult with data from temporary view based on map and reduce functions passed into parameters
func (*Database) Insert ¶
Insert creates new document in database. If inserted struct does not contain `_id` field (you may set it using json tag) couchdb will generate itself _id for this document and return it to you with revision. `fullCommit` overrides commit policy of couchdb instance, preferred value is `false`, more - http://docs.couchdb.org/en/1.6.1/config/couchdb.html#couchdb/delayed_commits Note: client takes only exported fields of a document (also all json flags are supported)
func (*Database) InsertMany ¶
func (db *Database) InsertMany(docs interface{}) ([]UpdateResult, error)
InsertMany is a shortcut to Update method. It saves documents to database, optional parameters are set to defaults. Consider use this method as primary insert operator
func (*Database) MustDeleteMany ¶
func (db *Database) MustDeleteMany(docs interface{}) ([]UpdateResult, error)
MustDeleteMany acts same like DeleteMany but ensures all documents to be deleted
func (*Database) MustInsertMany ¶
func (db *Database) MustInsertMany(docs interface{}) ([]UpdateResult, error)
MustInsertMany is a shortcut for Update method, acts like InsertMany but enshures atomicity of request.
func (*Database) Purge ¶
func (db *Database) Purge(o map[string][]string) (*PurgeResult, error)
Purge permanently removes the referenses to deleted documents from the database
func (*Database) Put ¶
Put creates new document with specified id or adds new revision to the existing one. Note: to add new revision you must specify the latest rev of the document you want to update, otherwise couchdb will answer 409(Conflict)
func (*Database) SaveAttachment ¶
func (db *Database) SaveAttachment(id, rev string, a *Attachment) (map[string]interface{}, error)
SaveAttachment uploads given attachment to document
func (*Database) SetRevsLimit ¶
SetRevsLimit sets the current database revision limit
func (*Database) SetSecurity ¶
func (db *Database) SetSecurity(o SecurityObject) error
SetSecurity sets database security object
func (*Database) Update ¶
func (db *Database) Update(docs interface{}, atomic, updateRev, fullCommit bool) ([]UpdateResult, error)
Update represents bulk operations on couchdb instance. It's highly customizable and not considered to use in common ways, use InsertMany or MustInsertMany instead.
If you are inserting documents that have field that represent it's revision ensure that it has json tag "omitempty" otherwise coucbdb will generate an error
func (*Database) ViewCleanup ¶
ViewCleanup removes view index files that are no longer required by couchdb instance
type DatabaseChanges ¶
type DatabaseChanges struct { LastSequence int `json:"last_seq"` Rows []DatabaseEvent `json:"results"` }
DatabaseChanges represents all changes related to current database
type DatabaseEvent ¶
type DatabaseEvent struct { Changes []map[string]string `json:"changes"` ID string `json:"id"` Seq int `json:"seq"` Deleted bool `json:"deleted"` }
DatabaseEvent represents a single change to current database
type DatabaseSecurity ¶
type DatabaseSecurity struct { DefaultSecurity // contains filtered or unexported fields }
DatabaseSecurity is a default security object but referred to the database
func (*DatabaseSecurity) AddAdmin ¶
func (sec *DatabaseSecurity) AddAdmin(login string) error
AddAdmin adds admin to database
func (*DatabaseSecurity) AddAdminRole ¶
func (sec *DatabaseSecurity) AddAdminRole(role string) error
AddAdminRole adds admin role to database
func (*DatabaseSecurity) AddMember ¶
func (sec *DatabaseSecurity) AddMember(login string) error
AddMember adds member to database
func (*DatabaseSecurity) AddMemberRole ¶
func (sec *DatabaseSecurity) AddMemberRole(role string) error
AddMemberRole adds membse role to database
func (*DatabaseSecurity) DeleteAdmin ¶
func (sec *DatabaseSecurity) DeleteAdmin(login string) error
DeleteAdmin deletes admin from database
func (*DatabaseSecurity) DeleteAdminRole ¶
func (sec *DatabaseSecurity) DeleteAdminRole(role string) error
DeleteAdminRole deletes admin role from database
func (*DatabaseSecurity) DeleteMember ¶
func (sec *DatabaseSecurity) DeleteMember(login string) error
DeleteMember deletes member from database
func (*DatabaseSecurity) DeleteMemberRole ¶
func (sec *DatabaseSecurity) DeleteMemberRole(role string) error
DeleteMemberRole deletes member role to database
type DefaultSecurity ¶
type DefaultSecurity struct { Admins SecurityGroup `json:"admins"` Members SecurityGroup `json:"members"` }
DefaultSecurity describes common security settings on a database
func (*DefaultSecurity) UpdateAdminRoles ¶
func (bs *DefaultSecurity) UpdateAdminRoles(login string, delete bool) error
UpdateAdminRoles allows to add/delete admin role into security object
func (*DefaultSecurity) UpdateAdmins ¶
func (bs *DefaultSecurity) UpdateAdmins(login string, delete bool) error
UpdateAdmins allows to add/delete admin into security object
func (*DefaultSecurity) UpdateMemberRoles ¶
func (bs *DefaultSecurity) UpdateMemberRoles(login string, delete bool) error
UpdateMemberRoles allows to add/delete member role into security object
func (*DefaultSecurity) UpdateMembers ¶
func (bs *DefaultSecurity) UpdateMembers(login string, delete bool) error
UpdateMembers allows to add/delete member role into security object
type Destination ¶
type Destination struct {
// contains filtered or unexported fields
}
Destination describes `id` of a document and allow to add some options to use in queries
func (*Destination) String ¶
func (d *Destination) String() (url string)
type PurgeResult ¶
type PurgeResult struct { PurgeSequence int `json:"purge_seq"` Purged map[string][]string `json:"purged"` }
PurgeResult provides object with result info of purge request
type ReplicationResult ¶
type ReplicationResult struct { History []map[string]interface{} `json:"history"` Ok bool `json:"ok"` ReplicationVer int `json:"replication_id_version"` SessionID string `json:"session_id"` SourceLastSeq int `json:"source_last_seq"` }
ReplicationResult provides information about replication request
type SecurityGroup ¶
type SecurityGroup struct { Names []string `json:"names,omitempty"` Roles []string `json:"roles,omitempty"` }
SecurityGroup is a part of database security object
type SecurityObject ¶
type SecurityObject interface { UpdateAdmins(login string, delete bool) error UpdateMembers(login string, delete bool) error UpdateAdminRoles(role string, delete bool) error UpdateMemberRoles(role string, delete bool) error }
SecurityObject describes a common methods used by security mechanism in couchdb
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents couchdb instance and holds connection to it
func Connect ¶
Connect tries to connect to the couchdb server using given host, port and optionally Auth and default request timeout
func (*Server) Copy ¶
Copy returns a copy of server connection with same settings and auth information but with it's own http client instance todo: move this method to private!?
func (*Server) CreateDB ¶
CreateDB creates database on couchdb instance and if successful returns it
func (*Server) CreateUser ¶
func (srv *Server) CreateUser(user *UserRecord) error
CreateUser inserts user record to couchdb _users database
func (*Server) GetActiveTasks ¶
GetActiveTasks returns slice of maps describing tasks running on server
func (*Server) GetDBEvent ¶
GetDBEvent block execution of program until any db event on couchdb instance happens and then unmarshall this event into given variable. Query parameters are equal to official docs:
http://docs.couchdb.org/en/1.6.1/api/server/common.html#db-updates
Note: `timeout` option accepts milliseconds instead of seconds
func (*Server) GetDBEventChan ¶
func (srv *Server) GetDBEventChan() (c chan ServerEvent, err error)
GetDBEventChan returns channel that provides events happened on couchdb instance, it's thread safe to use in other goroutines. Also, you must close channel after all things done to release resourses and prevent memory leaks.
func (*Server) GetDatabase ¶
GetDatabase checks existence of specified database on couchdb instance and return it
func (*Server) GetLog ¶
GetLog returns you a buffer with given size, containing chunk from couchdb instance log file
func (*Server) GetMembership ¶
GetMembership returns lists of cluster and all nodes
func (*Server) Info ¶
func (srv *Server) Info() (*ServerInfo, error)
Info provides server information, also may be used to check server status
func (*Server) MustGetDatabase ¶
MustGetDatabase return database instance if it's present on server or creates new one
func (*Server) NewSession ¶
NewSession authenticates user and returns Session struct containing current session token
func (*Server) Replicate ¶
func (srv *Server) Replicate(source, target string, options Options) (*ReplicationResult, error)
Replicate provides replication management
type ServerEvent ¶
type ServerEvent struct { Name string `json:"db_name"` Ok bool `json:"ok"` Type string `json:"type"` }
ServerEvent represents couchdb instance information about databases
type ServerInfo ¶
type ServerInfo struct { Message string `json:"couchdb"` UUID string `json:"uuid"` Vendor interface{} `json:"vendor"` Version string `json:"version"` }
ServerInfo provides couchdb instance inforation
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session stores authentication cookie for current user at the CouchDB instance
func (Session) AddAuthHeaders ¶
AddAuthHeaders add cookie to request
type UpdateResult ¶
UpdateResult contains information about bulk request