Documentation
¶
Index ¶
- type Client
- func (t *Client) Authenticate(user string, password string) error
- func (t *Client) ConnectDatabase(ctx context.Context, name string) (*Database, error)
- func (t *Client) CreateDatabase(ctx context.Context, cmd *CreateDatabaseCmd) (*Database, error)
- func (t *Client) DestroyDatabase(ctx context.Context, name string) error
- func (t *Client) Ping() error
- func (t *Client) SetClient(client *http.Client) *Client
- func (t *Client) String() string
- type ClientConfig
- type ClusterInfo
- type ConnectionConfig
- type CreateDatabaseCmd
- type Database
- func (t *Database) Delete(ctx context.Context, id string, rev string) error
- func (t *Database) Find(ctx context.Context, format string, v ...interface{}) (*FindResult, error)
- func (t *Database) Get(ctx context.Context, id string, valuePtr interface{}) (string, error)
- func (t *Database) Info(ctx context.Context) (*DatabaseInfo, error)
- func (t *Database) Name() string
- func (t *Database) QueryView(ctx context.Context, query *ViewQuery) ([]ViewRow, error)
- func (t *Database) Set(ctx context.Context, id string, rev string, value interface{}) (string, error)
- func (t *Database) SetTimeout(timeout time.Duration)
- func (t *Database) String() string
- type DatabaseInfo
- type DatabaseMock
- func (t *DatabaseMock) Create(_ context.Context) error
- func (t *DatabaseMock) Destroy(_ context.Context) error
- func (t *DatabaseMock) Ensure(_ context.Context) error
- func (t *DatabaseMock) Exist(_ context.Context) (bool, error)
- func (t *DatabaseMock) Find(_ context.Context, format string, v ...interface{}) (*FindResult, error)
- func (t *DatabaseMock) Get(_ context.Context, id string, valuePtr interface{}) (string, error)
- func (t *DatabaseMock) Info(_ context.Context) (*DatabaseInfo, error)
- func (t *DatabaseMock) Set(_ context.Context, id string, rev string, value interface{}) (string, error)
- type DesignDocument
- type FindResult
- type Language
- type Range
- type SizesInfo
- type SortOrder
- type View
- type ViewQuery
- type ViewRow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is used to interact with a couchdb database.
func NewClientWithConfig ¶
func NewClientWithConfig(config ClientConfig) (*Client, error)
NewClientWithConfig instantiate a new 'Client' based on the given configs.
func (*Client) Authenticate ¶
Authenticate the requests.
func (*Client) ConnectDatabase ¶
ConnectDatabase will start a connection to the database with the given name.
func (*Client) CreateDatabase ¶
CreateDatabase will create a database with the given name.
If the database already exist, the method will fail with an error. If you want to ensure that the database exists, use the 'Ensure' method instead.
func (*Client) DestroyDatabase ¶
DestroyDatabase destroy the database given in parameter with all it content.
This method is idempotent. This means that if the database is not found it will return nil.
type ClientConfig ¶
type ClientConfig struct { URL string `yaml:"url"` User string `yaml:"user"` Password string `yaml:"password"` Connection ConnectionConfig `yaml:"connection"` }
ClientConfig is the configuration used to instantiate a 'Client' and its "Database".
type ClusterInfo ¶
type ClusterInfo struct { Replicas int `json:"n"` Shards int `json:"q"` ReadQuorums int `json:"r"` WriteQuorums int `json:"w"` }
ClusterInfo part of the Info response.
type ConnectionConfig ¶
type ConnectionConfig struct { MaxRetryNumber int `yaml:"max-retry-number"` CoolDownDuration time.Duration `yaml:"cooldown-duration"` }
ConnectionConfig specify the retry policy.
type CreateDatabaseCmd ¶
type CreateDatabaseCmd struct { Name string `json:"name" yaml:"name"` DesignDocuments map[string]DesignDocument `json:"design-documents" yaml:"design-documents"` }
CreateDatabaseCmd is the required configuration to create a new database.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is used to interact with a couchdb database.
func (*Database) Find ¶
func (t *Database) Find( ctx context.Context, format string, v ...interface{}, ) (*FindResult, error)
Find execute a map-reduce query and return the FindResult.
The query documentation can be found here : http://docs.couchdb.org/en/2.1.1/api/database/find.html
func (*Database) Get ¶
Get the value at the specified id and fill the given valuePtr with.
In case of success it will also return the current document revision.
The value will be deserialized using 'json.Unmarshal' so the 'json' tags set on your struct will be take in account.
func (*Database) Info ¶
func (t *Database) Info(ctx context.Context) (*DatabaseInfo, error)
Info return a bunch of metadata about the database.
func (*Database) Set ¶
func (t *Database) Set( ctx context.Context, id string, rev string, value interface{}, ) (string, error)
Set the given value with the given id.
Couchdb works with the MVCC model (http://docs.couchdb.org/en/2.1.1/intro/api.html#revisions) and so for updating and already existing document, it need its revision.
If it the first time the key is used, keep the rev field empty. If a document have been already saved with this key, give the revision returned during the previous call.
In case of success it return the revision of the newly saved document.
The value will be serialized using 'json.Marshal' so the 'json' tags set in your struct will be take in account.
func (*Database) SetTimeout ¶
SetTimeout for request deadline.
Once the timeout is reached, the request is aborted via the context. An empty duration is equivalent to no timeout set.
type DatabaseInfo ¶
type DatabaseInfo struct { Name string `json:"db_name"` Cluster ClusterInfo `json:"cluster"` CompactRunning bool `json:"compact_running"` DiskFormatVersion int `json:"disk_format_version"` DocCount int `json:"doc_count"` DocDelCount int `json:"doc_del_count"` InstanceStartTime string `json:"instance_start_time"` PurgeSeq int `json:"purge_seq"` Sizes SizesInfo `json:"sizes"` UpdateSeq string `json:"update_seq"` }
DatabaseInfo returned by the Info method.
type DatabaseMock ¶
DatabaseMock is a mock implementation of 'Database' with the 'testify/mock' lib.
func (*DatabaseMock) Create ¶
func (t *DatabaseMock) Create(_ context.Context) error
Create is a mock implementation of 'Database.Create' method.
func (*DatabaseMock) Destroy ¶
func (t *DatabaseMock) Destroy(_ context.Context) error
Destroy is a mock implementation of 'Database.Destroy' method.
func (*DatabaseMock) Ensure ¶
func (t *DatabaseMock) Ensure(_ context.Context) error
Ensure is a mock implementation of 'Database.Ensure' method.
func (*DatabaseMock) Exist ¶
func (t *DatabaseMock) Exist(_ context.Context) (bool, error)
Exist is a mock implementation of 'Database.Exist' method.
func (*DatabaseMock) Find ¶
func (t *DatabaseMock) Find( _ context.Context, format string, v ...interface{}, ) (*FindResult, error)
Find is a mock implementation of 'Database.Find' method.
func (*DatabaseMock) Info ¶
func (t *DatabaseMock) Info(_ context.Context) (*DatabaseInfo, error)
Info is a mock implementation of 'Database.Info' method.
type DesignDocument ¶
type DesignDocument struct { Language Language `json:"language" yaml:"language"` Views map[string]View `json:"views" yaml:"views"` }
DesignDocument regrouping views definitions.
type FindResult ¶
type FindResult struct { Bookmark string `json:"bookmark"` Docs []json.RawMessage `json:"docs"` Warning string `json:"warning"` }
FindResult is the Result of a 'Find' query.
It contains several documents which can be unmarshaled with a call to UnmarshalNext.
func NewFindResult ¶
func NewFindResult(raw io.Reader) (*FindResult, error)
NewFindResult instantiate aa new FindResult.
func (*FindResult) Next ¶
func (t *FindResult) Next() bool
Next return true is the next call document can be retrieved or not.
func (*FindResult) UnmarshalNext ¶
func (t *FindResult) UnmarshalNext(valuePtr interface{}) (string, string, error)
UnmarshalNext retrieve the next document and fill valuePtr with.
The value will be deserialized using 'json.Unmarshal' so the 'json' tags set on your struct will be take in account.
type SizesInfo ¶
type SizesInfo struct { Active int `json:"active"` External int `json:"external"` File int `json:"file"` }
SizesInfo part of the Info response.
type View ¶
type View struct { Map string `json:"map,omitempty" yaml:"map,omitempty"` Reduce string `json:"reduce,omitempty" yaml:"reduce,omitempty"` }
View definition.
type ViewQuery ¶
type ViewQuery struct { DesignDocument string ViewName string Limit uint Skip uint Order SortOrder Keys []interface{} Range *Range }
ViewQuery contains the parameters for query a view.
type ViewRow ¶
type ViewRow struct { ID string Key interface{} Value json.RawMessage }
ViewRow returned by a QueryView.