couch

package module
v0.0.0-...-78c41dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2016 License: MIT Imports: 16 Imported by: 9

README

Build Status GoDoc

This is a Golang client library for talking to CouchDB and Sync Gateway (which is largely CouchDB API compatible).

Originally forked from couch-go, though it's been heavily modified.

Documentation

Overview

Package couch provides a CouchDB API.

Index

Constants

This section is empty.

Variables

View Source
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

type ChangeHandler func(r io.Reader) interface{}

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"`
}

func ReadAllChanges

func ReadAllChanges(reader io.Reader) (Changes, error)

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

func Connect(dburl string) (Database, error)

Connect to the database at the given URL. example: couch.Connect("http://localhost:5984/testdb/")

func NewDatabase

func NewDatabase(host, port, name string) (Database, error)

NewDatabase connects to a CouchDB server and creates the specified database if it does not exist.

func (Database) BaseURL

func (p Database) BaseURL() string

BaseURL returns the URL to the database server containing this database.

func (Database) Bulk

func (p Database) Bulk(docs []interface{}) (results []Response, err error)

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) DBURL

func (p Database) DBURL() string

DBURL returns the URL to this specific database.

func (Database) Delete

func (p Database) Delete(id, rev string) error

Delete deletes document given by id and rev.

func (Database) DeleteDatabase

func (p Database) DeleteDatabase() error

DeleteDatabase deletes the given database and all documents

func (Database) Edit

func (p Database) Edit(d interface{}) (string, error)

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

func (p Database) EditWith(d interface{}, id, rev string) (string, error)

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) Exists

func (p Database) Exists() bool

Exists returns true if this database exists on the CouchDB server

func (Database) GetChanges

func (p Database) GetChanges(options map[string]interface{}) (changes Changes, err error)

Simpler interface to Changes feed which returns a Changes struct

func (Database) GetInfo

func (p Database) GetInfo() (DBInfo, error)

GetInfo gets the DBInfo for this database.

func (Database) Insert

func (p Database) Insert(d interface{}) (string, string, error)

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

func (p Database) InsertWith(d interface{}, id string) (string, string, error)

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

func (p Database) LastSequence() (interface{}, error)

Reads the entire Changes feed to find the LastSequence

func (Database) Query

func (p Database) Query(view string, options map[string]interface{}, results interface{}) error

Query executes and unmarshals a view request.

func (Database) QueryIds

func (p Database) QueryIds(view string, options map[string]interface{}) ([]string, error)

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) Retrieve

func (p Database) Retrieve(id string, d interface{}) error

Retrieve unmarshals the document matching id to the given interface

func (Database) RetrieveAttachment

func (p Database) RetrieveAttachment(id string, name string) (io.Reader, error)

func (Database) Running

func (p Database) Running() bool

Running returns true if CouchDB is running (ignores Database.Name)

func (Database) ViewURL

func (p Database) ViewURL(view string, params map[string]interface{}) (string, error)

ViewURL builds a URL for a view with the given ddoc, view name, and parameters.

type DocID

type DocID string

DocID is a string type that isn't escaped in a view param

type Response

type Response struct {
	Ok     bool
	ID     string
	Rev    string
	Error  string
	Reason string
}

Response represents a typical command response from against a CouchDB server.

type RetryDoneMetric

type RetryDoneMetric func() bool

type RetryRefresh

type RetryRefresh func() error

type RetryUpdater

type RetryUpdater func()

type Row

type Row struct {
	ID  *string
	Key *string
}

Row represents a single row in a view response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL