couch

package module
v0.0.0-...-8251128 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2016 License: MIT Imports: 14 Imported by: 20

README

This is the CouchDB API I use when I do CouchDB stuff.

I forked this originally couch-go, though it's been heavily modified.

Read docs at godoc.org.

Coverage Status

Documentation

Overview

Package couch provides a CouchDB API.

Index

Constants

This section is empty.

Variables

View Source
var HTTPClient = http.DefaultClient

HTTP Client used by typical requests.

Defaults to http.DefaultClient

Functions

This section is empty.

Types

type ChangeHandler

type ChangeHandler func(r io.Reader) int64

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

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{}) ([]Response, 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) 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) 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) 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) 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 Row

type Row struct {
	ID  *string
	Key *string
}

Row represents a single row in a view response

Jump to

Keyboard shortcuts

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