cloudant

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

README

go-cloudant

A Cloudant library for Golang.

Forked from cloudant-labs and modified to align closer to NodeJS nano library. This library is not complete, may change in incompatible ways in future versions, and comes with no support.

Build Status

Features:

  • Session authentication
  • Keep-Alive & Connection Pooling
  • Configurable request retrying
  • Hard limit on request concurrency
  • Stream /_changes, /_all_docs, and other views
  • Manage /_bulk_docs uploads

Installation

go get github.com/barshociaj/go-cloudant

Getting Started

// create a Cloudant client with default configuration:
//   - concurrency:                     5
//   - maximum retries per request:     3
//   - random retry delay minimum:      5  seconds
//   - random retry delay maximum:      30 seconds
client, err := cloudant.NewClient("user123", "pa55w0rd01", "https://user123.cloudant.com")

// OR provide any number of custom client options
//
// client, err := cloudant.NewClient("user123", "pa55w0rd01", "https://user123.cloudant.com", cloudant.ClientConcurrency(20), cloudant.ClientRetryCountMax(5), cloudant.ClientRetryDelayMin(10), cloudant.ClientRetryDelayMax(60))

Database functions

client.Destroy(dbName)

Delete existing database

err := client.Destroy("my_db")
client.Exists(dbName)

Checks if database exists

exists, err := client.Exists("my_db")
client.Info(dbName)

Retrieve database info

info, err := client.Info("my_db")
fmt.Println(info.DocCount) // prints the number of documents in the database

client.List(dbsQuery)

List existing databases

dbList, err := client.List(cloudant.NewDBsQuery())
for _, name := range *dbList {
    fmt.Println(name) // prints database names
}
client.Use(dbName)

Use existing database:

db, err := client.Use("my_database")
client.UseOrCreate(dbName)

Create (if does not exist) and use a database:

db, err := client.UseOrCreate("my_database")
db.Changes(changesQuery)

Get changes feed from the database

q := cloudant.NewChangesQuery().IncludeDocs()

changes, err := db.Changes(q)

for {
    change, more := <-changes
    if more {
        fmt.Println(change.Seq, change.Id, change.Rev)  // prints change 'seq', 'id' and 'rev'

        // Doc body
        str, _ := json.MarshalIndent(change.Doc, "", "  ")
        fmt.Printf("%s\n", str)
    } else {
        break
    }
}
db.NewFollower(seq)

Creates a new changes feed follower that runs in continuous mode, emitting events from the changes feed on a channel. Its aims is to stay running until told to terminate with changes.Close()

// Only generate a Seq ID every 100 changes
follower := db.NewFollower(100)
changes, err := follower.Follow()
if err != nil {
    fmt.Println(err)
    return
}

for {
    changeEvent := <-changes

    switch changeEvent.EventType {
    case cloudant.ChangesHeartbeat:
        fmt.Println("tick")
    case cloudant.ChangesError:
        fmt.Println(changeEvent.Err)
    case cloudant.ChangesTerminated:
        fmt.Println("terminated; resuming from last known sequence id")
        changes, err = follower.Follow()
        if err != nil {
            fmt.Println("resumption error ", err)
            return
        }
    case cloudant.ChangesInsert:
        fmt.Printf("INSERT %s\n", changeEvent.Meta.ID)
    case cloudant.ChangesDelete:
        fmt.Printf("DELETE %s\n", changeEvent.Meta.ID)
    default:
        fmt.Printf("UPDATE %s\n", changeEvent.Meta.ID)
    }
}

Document functions

db.Destroy(docID, rev)

Removes a document from database

err := db.Destroy("my_doc_id", "2-xxxxxxx")
db.Get(docID, docQuery, doc)

Gets a document from Cloudant whose _id is docID and unmarshals it into doc struct

type Doc struct {
    Id     string    `json:"_id"`
    Rev    string    `json:"_rev"`
    Foo    string    `json:"foo"`
}

doc = new(Doc)
err = db.Get("my_doc_id", cloudant.NewDocQuery(), doc)

fmt.Println(doc.Foo)  // prints 'foo' key
db.Insert(doc)

Inserts myDoc in the database

myDoc := &Doc{
    ID:     "my_doc_id",
    Foo:    "bar",
}

newRev, err := db.Insert(myDoc)

fmt.Println(newRev)  // prints '_rev' of new document revision
db.InsertEscaped(doc)

Inserts myDoc in the database and escapes HTML in strings

newRev, err := db.InsertEscaped(myDoc)
db.InsertRaw(json)

Inserts raw JSON ([]byte) in the database

json := []byte(`{
		"_id": "_design/test_design_doc",
		"language": "javascript",
		"views": {
			"start_with_one": {
				"map": "function (doc) { if (doc._id.indexOf('-01') > 0) emit(doc._id, doc.foo) }"
			}
		}
	  }`)

newRev, err := db.InsertRaw(json)
db.Bulk(batchSize, batchMaxBytes, flushSecs)

Bulk operations(update/delete/insert) on the database's /_bulk_docs endpoint

myDoc1 := Doc{
    ID:     "doc1",
    Foo:    "bar",
}

myDoc2 := Doc{
    ID:     "doc2",
    Foo:    "bar",
}

myDoc3 := Doc{
    ID:     "doc3",
    Foo:    "bar",
}

uploader := db.Bulk(50, 1048576, 60) // new uploader using batch size 50, max batch size 1MB, flushing documents to server every 60 seconds

// Note: workers only flush their document batch to the server:
//  1)  periodically (set to -1 to disable).
//  2)  when the maximum number of documents per batch is reached.
//  3)  when the maximum batch size (in bytes) is reached (set to -1 to disable).
//  4)  if a document is uploaded using `.UploadNow(doc)`.
//  5)  if a client calls `.Flush()` or `.Stop()`.

uploader.FireAndForget(myDoc1)

upload.Flush() // blocks until all received documents have been uploaded

r2 := uploader.UploadNow(myDoc2) // uploaded as soon as it's received by a worker

r2.Wait()
if r2.Error != nil {
    fmt.Println(r2.Response.Id, r2.Response.Rev) // prints new document '_id' and 'rev'
}

r3 := uploader.Upload(myDoc3) // queues until the worker creates a full batch of 50 documents

upload.AsyncFlush() // asynchronously uploads all received documents

upload.Stop() // blocks until all documents have been uploaded and workers have stopped

r3.Wait()
if r3.Error != nil {
    fmt.Println(r3.Response.Id, r3.Response.Rev) // prints new document '_id' and 'rev'
}

Views functions

db.List(viewQuery)

List all the docs in the database (_all_docs view)

rows, err := db.List(cloudant.NewViewQuery())

// OR include some query options...
//
// q := cloudant.NewViewQuery().
//        Limit(123).
//        StartKey("foo1").
//        EndKey("foo2")
//
// rows, err := db.List(q)

for {
    row, more := <-rows
    if more {
        fmt.Println(row.ID, row.Value.Rev)  // prints document 'id' and 'rev'
    } else {
        break
    }
}
db.View(designName, viewName, viewQuery, view)

Calls a view of the specified designName and decodes the result using provided interface

type MyRow struct {
	ID    string `json:"id"`
	Key   string `json:"key"`
	Value string `json:"value"`
	Doc   MyDoc  `json:"doc"`
}
type MyDoc struct {
	ID  string `json:"_id,omitempty"`
	Rev string `json:"_rev,omitempty"`
	Foo string `json:"foo" binding:"required"`
}


myView := new(DocsView)
q := cloudant.NewViewQuery().
    Descending().
    Key("foo1").
    Limit(1).
    IncludeDocs()

rows, err := db.View("my_design_name", "my_view_name", q, myView)

for {
    row, more := <-rows
    if more {
        r := new(MyRow)
        err = json.Unmarshal(row.([]byte), r)
        if err == nil {
            fmt.Println(r.Doc.ID, r.Doc.Rev, r.Doc.Foo)  // prints document 'id', 'rev', and 'foo' value
        }
    } else {
        break
    }
}
db.ViewRaw(designName, viewName, viewQuery)

Calls a view of the specified designName and returns raw []byte response. This allows querying views with arbitrary output such as when using reduce.

import "github.com/buger/jsonparser"

response, err := db.ViewRaw("my_design_name", "my_view_name", cloudant.NewViewQuery())

if err != nil {
    value, decodeErr := jsonparser.Get(response, "total_rows")
}

Documentation

Index

Constants

View Source
const (
	// ChangesInsert is a new document, with _rev starting with "1-"
	ChangesInsert = iota
	// ChangesUpdate is a new revison of an existing document
	ChangesUpdate
	// ChangesDelete is a document deletion
	ChangesDelete
	// ChangesHeartbeat is an empty line sent to keep the connection open
	ChangesHeartbeat
	// ChangesTerminated means far end closed the connection
	ChangesTerminated
	ChangesError
)

Constants defining the possible event types in a changes feed

Variables

View Source
var LogFunc = log.Printf

LogFunc is a function that logs the provided message with optional fmt.Sprintf-style arguments. By default, logs to the default log.Logger.

Functions

func Endpoint

func Endpoint(base url.URL, pathStr string, params url.Values) (string, error)

Endpoint is a convenience function to build url-strings

func UnescapedHTMLJSONMarshal

func UnescapedHTMLJSONMarshal(t interface{}) ([]byte, error)

UnescapedHTMLJSONMarshal marshals JSON without escaping HTML

Types

type BulkDocsRequest

type BulkDocsRequest struct {
	Docs     []interface{} `json:"docs"`
	NewEdits bool          `json:"new_edits"`
}

BulkDocsRequest is the JSON body of a request to the _bulk_docs endpoint

type BulkDocsResponse

type BulkDocsResponse struct {
	Error  string `json:"error,omitempty"`
	ID     string `json:"id"`
	Reason string `json:"reason,omitempty"`
	Rev    string `json:"rev,omitempty"`
}

BulkDocsResponse is the JSON body of the response from the _bulk_docs endpoint

type BulkJob

type BulkJob struct {
	Error error

	Response *BulkDocsResponse
	// contains filtered or unexported fields
}

BulkJob represents the state of a single document to be uploaded as part of a batch

func (*BulkJob) Wait

func (j *BulkJob) Wait()

Wait blocks while the job is being executed.

type BulkJobI

type BulkJobI interface {
	Wait()
	// contains filtered or unexported methods
}

BulkJobI ...

type Change

type Change struct {
	ID      string
	Rev     string
	Seq     string
	Deleted bool
	Doc     map[string]interface{} // Only present if Changes() called with include_docs=true
}

Change represents a part returned by _changes

type ChangeEvent

type ChangeEvent struct {
	EventType int
	Meta      *DocumentMeta
	Seq       string
	Doc       map[string]interface{}
	Err       error
}

ChangeEvent is the message structure delivered by the Read function

type ChangeRow

type ChangeRow struct {
	ID      string                 `json:"id"`
	Seq     string                 `json:"seq"` // If using CouchDB1.6, this is a number
	Changes []ChangeRowChanges     `json:"changes"`
	Deleted bool                   `json:"deleted"`
	Doc     map[string]interface{} `json:"doc"`
}

ChangeRow represents a part returned by _changes

func (*ChangeRow) UnmarshalJSON

func (c *ChangeRow) UnmarshalJSON(data []byte) error

UnmarshalJSON is here for coping with CouchDB1.6's sequence IDs being numbers, not strings as in Cloudant and CouchDB2.X.

See https://play.golang.org/p/BytXCeHMvt

type ChangeRowChanges

type ChangeRowChanges struct {
	Rev string `json:"rev"`
}

ChangeRowChanges represents a part returned by _changes

type ChangesQuery

type ChangesQuery struct {
	URLValues   url.Values
	DocIDValues []string
}

ChangesQuery object helps build Cloudant ChangesQuery parameters

func NewChangesQuery

func NewChangesQuery() *ChangesQuery

NewChangesQuery is a shortcut to create new Cloudant ChangesQuery object with no parameters

func (*ChangesQuery) Conflicts

func (q *ChangesQuery) Conflicts() *ChangesQuery

Conflicts applies conflicts=true parameter to Cloudant ChangesQuery

func (*ChangesQuery) Descending

func (q *ChangesQuery) Descending() *ChangesQuery

Descending applies descending=true parameter to Cloudant ChangesQuery

func (*ChangesQuery) DocIDs

func (q *ChangesQuery) DocIDs(docIDs []string) *ChangesQuery

DocIDs applies doc_ids=(doc_ids) parameter to Cloudant ChangesQuery

func (*ChangesQuery) Feed

func (q *ChangesQuery) Feed(feed string) *ChangesQuery

Feed applies feed=(feed) parameter to Cloudant ChangesQuery

func (*ChangesQuery) Filter

func (q *ChangesQuery) Filter(filter string) *ChangesQuery

Filter applies filter=(filter) parameter to Cloudant ChangesQuery

func (*ChangesQuery) Heartbeat

func (q *ChangesQuery) Heartbeat(heartbeat int) *ChangesQuery

Heartbeat applies heartbeat parameter to Cloudant ChangesQuery

func (*ChangesQuery) IncludeDocs

func (q *ChangesQuery) IncludeDocs() *ChangesQuery

IncludeDocs applies include_docs=true parameter to Cloudant ChangesQuery

func (*ChangesQuery) Limit

func (q *ChangesQuery) Limit(lim int) *ChangesQuery

Limit applies limit parameter to Cloudant ChangesQuery

func (*ChangesQuery) SeqInterval

func (q *ChangesQuery) SeqInterval(interval int) *ChangesQuery

SeqInterval applies seq_interval parameter to Cloudant ChangesQuery

func (*ChangesQuery) Since

func (q *ChangesQuery) Since(since string) *ChangesQuery

Since applies since=(since) parameter to Cloudant ChangesQuery

func (*ChangesQuery) Style

func (q *ChangesQuery) Style(style string) *ChangesQuery

Style applies style=(style) parameter to Cloudant ChangesQuery

func (*ChangesQuery) Timeout

func (q *ChangesQuery) Timeout(timeout int) *ChangesQuery

Timeout applies seq_interval parameter to Cloudant ChangesQuery

type Client added in v0.3.0

type Client struct {
	// contains filtered or unexported fields
}

Client is the representation of a client connection

func NewClient added in v0.3.0

func NewClient(username, password, rootStrURL string, options ...ClientOption) (*Client, error)

NewClient returns a new Cloudant client

func (*Client) Destroy added in v0.3.0

func (c *Client) Destroy(databaseName string) error

Destroy deletes a specified database.

func (*Client) Execute added in v0.3.0

func (c *Client) Execute(job *Job)

Execute submits a job for execution. The client must call `job.Wait()` before attempting access the response attribute. Always call `job.Close()` to ensure the underlying connection is terminated.

func (*Client) Exists added in v0.3.0

func (c *Client) Exists(databaseName string) (bool, error)

Exists checks the existence of a specified database. Returns true if the database exists, else false.

func (*Client) Info added in v0.3.0

func (c *Client) Info(databaseName string) (*Info, error)

Info returns database information. See https://console.bluemix.net/docs/services/Cloudant/api/database.html#getting-database-details

func (*Client) List added in v0.3.0

func (c *Client) List(q *DBsQuery) (*[]string, error)

List returns a list of all DBs

func (*Client) LogIn added in v0.3.0

func (c *Client) LogIn() error

LogIn creates a session.

func (*Client) LogOut added in v0.3.0

func (c *Client) LogOut()

LogOut deletes the current session.

func (*Client) Ping added in v0.3.0

func (c *Client) Ping() (err error)

Ping can be used to check whether a server is alive. It sends an HTTP HEAD request to the server's URL.

func (*Client) Stop added in v0.3.0

func (c *Client) Stop()

Stop kills all running workers. Once called the client is no longer able to execute new jobs.

func (*Client) Use added in v0.3.0

func (c *Client) Use(databaseName string) (*Database, error)

Use returns a database. It is assumed to exist.

func (*Client) UseOrCreate added in v0.3.0

func (c *Client) UseOrCreate(databaseName string) (*Database, error)

UseOrCreate returns a database. If the database doesn't exist on the server then it will be created.

type ClientOption added in v0.3.0

type ClientOption func(*Client)

ClientOption is a functional option setter for Client

func ClientConcurrency added in v0.3.0

func ClientConcurrency(workerCount int) ClientOption

ClientConcurrency overrides default workerCount Client option

func ClientHTTPClient added in v0.3.0

func ClientHTTPClient(httpClient *http.Client) ClientOption

ClientHTTPClient overrides default httpClient option

func ClientRetryCountMax added in v0.3.0

func ClientRetryCountMax(retryCountMax int) ClientOption

ClientRetryCountMax overrides default retryCountMax Client option

func ClientRetryDelayMax added in v0.3.0

func ClientRetryDelayMax(retryDelayMax int) ClientOption

ClientRetryDelayMax overrides default retryDelayMax Client option

func ClientRetryDelayMin added in v0.3.0

func ClientRetryDelayMin(retryDelayMin int) ClientOption

ClientRetryDelayMin overrides default retryDelayMin Client option

type CouchError

type CouchError struct {
	Err        string `json:"error"`
	Reason     string `json:"reason"`
	StatusCode int
}

CouchError is a server error response

func (*CouchError) Error

func (e *CouchError) Error() string

Error() implements the error interface

type CredentialsExpiredResponse

type CredentialsExpiredResponse struct {
	Error string `json:"error"`
}

CredentialsExpiredResponse holds credentials error message

type DBsQuery

type DBsQuery struct {
	URLValues url.Values
}

DBsQuery object helps build Cloudant DBsQuery parameters

func NewDBsQuery

func NewDBsQuery() *DBsQuery

NewDBsQuery is a shortcut to create new Cloudant DBsQuery object with no parameters

func (*DBsQuery) Descending

func (q *DBsQuery) Descending() *DBsQuery

Descending applies descending=true parameter to Cloudant DBsQuery

func (*DBsQuery) EndKey

func (q *DBsQuery) EndKey(endKey string) *DBsQuery

EndKey applies endkey=(key) parameter to Cloudant DBsQuery

func (*DBsQuery) InclusiveEnd

func (q *DBsQuery) InclusiveEnd() *DBsQuery

InclusiveEnd applies inclusive_end=true parameter to Cloudant DBsQuery

func (*DBsQuery) Limit

func (q *DBsQuery) Limit(lim int) *DBsQuery

Limit applies limit parameter to Cloudant DBsQuery

func (*DBsQuery) Skip

func (q *DBsQuery) Skip(skip int) *DBsQuery

Skip applies skip=(number) parameter to Cloudant DBsQuery

func (*DBsQuery) StartKey

func (q *DBsQuery) StartKey(startKey string) *DBsQuery

StartKey applies startkey=(key) parameter to Cloudant DBsQuery

type Database

type Database struct {
	Name string
	URL  *url.URL
	// contains filtered or unexported fields
}

Database holds a reference to an authenticated client connection and the name of a remote database

func (*Database) Bulk

func (d *Database) Bulk(batchSize int, batchMaxBytes int, flushSecs int) *Uploader

Bulk returns a new bulk document uploader.

func (*Database) Changes

func (d *Database) Changes(q *ChangesQuery) (<-chan *Change, error)

Changes returns a channel in which Change types can be received. See: https://console.bluemix.net/docs/services/Cloudant/api/database.html#get-changes

func (*Database) Destroy

func (d *Database) Destroy(documentID, rev string) error

Destroy a document with a specified revision.

func (*Database) Get

func (d *Database) Get(documentID string, q *DocQuery, target interface{}) error

Get a document from the database. See: https://console.bluemix.net/docs/services/Cloudant/api/document.html#read

func (*Database) Insert

func (d *Database) Insert(document interface{}) (*DocumentMeta, error)

Insert a document without escaped HTML.

func (*Database) InsertEscaped

func (d *Database) InsertEscaped(document interface{}) (*DocumentMeta, error)

InsertEscaped a document with escaped HTML.

func (*Database) InsertRaw

func (d *Database) InsertRaw(jsonDocument []byte) (*DocumentMeta, error)

InsertRaw posts raw input to Cloudant. Input may have json attributes '_id' and '_rev'. If no '_id' is given the database will generate one for you.

func (*Database) List

func (d *Database) List(q *ViewQuery) (<-chan interface{}, error)

List returns a channel in which AllRow types can be received.

func (*Database) NewFollower

func (d *Database) NewFollower(interval int) *Follower

NewFollower creates a Follower on database's changes

func (*Database) View

func (d *Database) View(designName, viewName string, q *ViewQuery) (<-chan interface{}, error)

View returns a channel in which AllRow types can be received.

func (*Database) ViewRaw

func (d *Database) ViewRaw(designName, viewName string, q *ViewQuery) ([]byte, error)

ViewRaw allows querying views with arbitrary output such as when using reduce

type DocQuery

type DocQuery struct {
	URLValues url.Values
}

DocQuery object helps build Cloudant DocQuery parameters

func NewDocQuery

func NewDocQuery() *DocQuery

NewDocQuery is a shortcut to create new Cloudant DocQuery object with no parameters

func (*DocQuery) AttEncodingInfo

func (q *DocQuery) AttEncodingInfo() *DocQuery

AttEncodingInfo applies att_encoding_info=true parameter to Cloudant DocQuery

func (*DocQuery) Attachments

func (q *DocQuery) Attachments() *DocQuery

Attachments applies attachments=true parameter to Cloudant DocQuery

func (*DocQuery) AttsSince added in v0.3.0

func (q *DocQuery) AttsSince(since []string) *DocQuery

AttsSince applies attsSince=(since) parameter to Cloudant ViewQuery

func (*DocQuery) Conflicts

func (q *DocQuery) Conflicts() *DocQuery

Conflicts applies conflicts=true parameter to Cloudant DocQuery

func (*DocQuery) DeletedConflicts

func (q *DocQuery) DeletedConflicts() *DocQuery

DeletedConflicts applies deleted_conflicts=true parameter to Cloudant DocQuery

func (*DocQuery) Latest

func (q *DocQuery) Latest() *DocQuery

Latest applies latest=true parameter to Cloudant DocQuery

func (*DocQuery) LocalSeq

func (q *DocQuery) LocalSeq() *DocQuery

LocalSeq applies local_seq=true parameter to Cloudant DocQuery

func (*DocQuery) Meta

func (q *DocQuery) Meta() *DocQuery

Meta applies meta=true parameter to Cloudant DocQuery

func (*DocQuery) OpenRevs added in v0.3.0

func (q *DocQuery) OpenRevs(revs []string) *DocQuery

OpenRevs applies open_revs=(revs) parameter to Cloudant DocQuery

func (*DocQuery) Rev

func (q *DocQuery) Rev(rev string) *DocQuery

Rev applies rev=(rev) parameter to Cloudant DocQuery

func (*DocQuery) Revs

func (q *DocQuery) Revs() *DocQuery

Revs applies revs=true parameter to Cloudant DocQuery

func (*DocQuery) RevsInfo

func (q *DocQuery) RevsInfo() *DocQuery

RevsInfo applies revs_info=true parameter to Cloudant DocQuery

func (*DocQuery) Skip

func (q *DocQuery) Skip(skip int) *DocQuery

Skip applies skip=(number) parameter to Cloudant DocQuery

type DocumentMeta

type DocumentMeta struct {
	ID  string `json:"id"`
	Rev string `json:"rev"`
}

DocumentMeta is a CouchDB id/rev pair

type Follower

type Follower struct {
	// contains filtered or unexported fields
}

Follower is the orchestrator

func (*Follower) Close

func (f *Follower) Close()

Close will terminate the Follower

func (*Follower) Follow

func (f *Follower) Follow() (<-chan *ChangeEvent, error)

Follow starts listening to the changes feed

type Info

type Info struct {
	IsCompactRunning  bool   `json:"compact_running"`
	DBName            string `json:"db_name"`
	DiskFromatVersion int    `json:"disk_format_version"`
	DiskSize          int    `json:"disk_size"`
	DocCount          int    `json:"doc_count"`
	DocDelCount       int    `json:"doc_del_count"`
	PurgeSeq          int    `json:"purge_seq"`
	Sizes             Sizes  `json:"sizes"`
	UpdateSeq         string `json:"update_seq"`
}

Info represents the account meta-data

type Job

type Job struct {
	// contains filtered or unexported fields
}

Job wraps all requests

func CreateJob

func CreateJob(request *http.Request) *Job

CreateJob makes a new Job from a HTTP request.

func UploadBulkDocs

func UploadBulkDocs(bulkDocs *BulkDocsRequest, database *Database) (result *Job, err error)

UploadBulkDocs performs a synchronous _bulk_docs POST

func (*Job) Close

func (j *Job) Close()

Close closes the response body reader to prevent a memory leak, even if not used

func (*Job) Response

func (j *Job) Response() *http.Response

Response returns the http response

func (*Job) Wait

func (j *Job) Wait()

Wait blocks while the job is being executed.

type Sizes

type Sizes struct {
	File     int `json:"file"`
	External int `json:"external"`
	Active   int `json:"active"`
}

Sizes represents the sizes part of database info

type Uploader

type Uploader struct {
	NewEdits bool
	// contains filtered or unexported fields
}

Uploader is where Mr Smartypants live

func (*Uploader) AsyncFlush

func (u *Uploader) AsyncFlush()

AsyncFlush asynchronously uploads all received documents.

func (*Uploader) BulkUploadSimple

func (u *Uploader) BulkUploadSimple(docs []interface{}) ([]BulkDocsResponse, error)

BulkUploadSimple does a one-shot synchronous bulk upload

func (*Uploader) FireAndForget

func (u *Uploader) FireAndForget(doc interface{})

FireAndForget adds a document to the upload queue ready for processing by the upload worker(s).

func (*Uploader) Flush

func (u *Uploader) Flush()

Flush blocks until all received documents have been uploaded.

func (*Uploader) Stop

func (u *Uploader) Stop()

Stop uploads all received documents and then terminates the upload worker(s)

func (*Uploader) Upload

func (u *Uploader) Upload(doc interface{}) *BulkJob

Upload adds a document to the upload queue ready for processing by the upload worker(s). A BulkJob type is returned to the client so that progress can be monitored.

func (*Uploader) UploadNow

func (u *Uploader) UploadNow(doc interface{}) *BulkJob

UploadNow adds a priority document to the upload queue ready for processing by the upload worker(s). Once received by a worker it triggers the upload of the entire batch (regardless of the current batch size). A BulkJob type is returned to the client so that progress can be monitored.

type ViewQuery

type ViewQuery struct {
	URLValues url.Values
	KeyValues []string
}

ViewQuery object helps build Cloudant ViewQuery parameters

func NewViewQuery

func NewViewQuery() *ViewQuery

NewViewQuery is a shortcut to create new Cloudant ViewQuery object with no parameters

func (*ViewQuery) Conflicts

func (q *ViewQuery) Conflicts() *ViewQuery

Conflicts applies conflicts=true parameter to Cloudant ViewQuery

func (*ViewQuery) DeletedConflicts

func (q *ViewQuery) DeletedConflicts() *ViewQuery

DeletedConflicts applies deleted_conflicts=true parameter to Cloudant ViewQuery

func (*ViewQuery) Descending

func (q *ViewQuery) Descending() *ViewQuery

Descending applies descending=true parameter to Cloudant ViewQuery

func (*ViewQuery) DoNotUpdate

func (q *ViewQuery) DoNotUpdate() *ViewQuery

DoNotUpdate applies update=false parameter to Cloudant ViewQuery - return results without updating the view

func (*ViewQuery) EndKey

func (q *ViewQuery) EndKey(endKey string) *ViewQuery

EndKey applies endkey=(key) parameter to Cloudant ViewQuery

func (*ViewQuery) EndKeyDocID

func (q *ViewQuery) EndKeyDocID(endKeyDocID string) *ViewQuery

EndKeyDocID applies endkey_docid=(key) parameter to Cloudant ViewQuery

func (*ViewQuery) Group

func (q *ViewQuery) Group() *ViewQuery

Group applies group=true parameter to Cloudant ViewQuery

func (*ViewQuery) GroupLevel

func (q *ViewQuery) GroupLevel(groupLevel int) *ViewQuery

GroupLevel applies group_level=(number) parameter to Cloudant ViewQuery

func (*ViewQuery) IncludeDocs

func (q *ViewQuery) IncludeDocs() *ViewQuery

IncludeDocs applies include_docs=true parameter to Cloudant ViewQuery

func (*ViewQuery) InclusiveEnd

func (q *ViewQuery) InclusiveEnd() *ViewQuery

InclusiveEnd applies inclusive_end=true parameter to Cloudant ViewQuery

func (*ViewQuery) Key

func (q *ViewQuery) Key(key string) *ViewQuery

Key applies key=(key) parameter to Cloudant ViewQuery

func (*ViewQuery) Keys

func (q *ViewQuery) Keys(keys []string) *ViewQuery

Keys applies keys=(keys) parameter to Cloudant ViewQuery

func (*ViewQuery) Limit

func (q *ViewQuery) Limit(lim int) *ViewQuery

Limit applies limit parameter to Cloudant ViewQuery

func (*ViewQuery) Meta

func (q *ViewQuery) Meta() *ViewQuery

Meta applies meta=true parameter to Cloudant ViewQuery

func (*ViewQuery) R

func (q *ViewQuery) R(r int) *ViewQuery

R applies r=(number) parameter to Cloudant ViewQuery

func (*ViewQuery) Reduce

func (q *ViewQuery) Reduce() *ViewQuery

Reduce applies reduce=true parameter to Cloudant ViewQuery

func (*ViewQuery) RevsInfo

func (q *ViewQuery) RevsInfo() *ViewQuery

RevsInfo applies revs_info=true parameter to Cloudant ViewQuery

func (*ViewQuery) Skip

func (q *ViewQuery) Skip(skip int) *ViewQuery

Skip applies skip=(number) parameter to Cloudant ViewQuery

func (*ViewQuery) Stable

func (q *ViewQuery) Stable() *ViewQuery

Stable applies stable=true parameter to Cloudant ViewQuery

func (*ViewQuery) Stale

func (q *ViewQuery) Stale() *ViewQuery

Stale applies stale=ok parameter to Cloudant ViewQuery

func (*ViewQuery) StaleUpdateAfter

func (q *ViewQuery) StaleUpdateAfter() *ViewQuery

StaleUpdateAfter applies stale=update_after parameter to Cloudant ViewQuery

func (*ViewQuery) StartKey

func (q *ViewQuery) StartKey(startKey string) *ViewQuery

StartKey applies startkey=(key) parameter to Cloudant ViewQuery

func (*ViewQuery) StartKeyDocID

func (q *ViewQuery) StartKeyDocID(startKeyDocID string) *ViewQuery

StartKeyDocID applies startkey_docid=(key) parameter to Cloudant ViewQuery

func (*ViewQuery) UpdateLazy

func (q *ViewQuery) UpdateLazy() *ViewQuery

UpdateLazy applies update=lazy parameter to Cloudant ViewQuery - return the view results without waiting for an update, but update them immediately after the request

type ViewRow

type ViewRow struct {
	ID    string      `json:"id"`
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
	Doc   interface{} `json:"doc"`
}

ViewRow contains one row from Cloudant view

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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