Categorygithub.com/codeocean/kivik
modulepackage
1.8.1
Repository: https://github.com/codeocean/kivik.git
Documentation: pkg.go.dev

# README

Build Status Codecov Website

Kivik

Package kivik provides a generic interface to CouchDB or CouchDB-like databases.

The kivik package must be used in conjunction with a database driver.

The kivik driver system is modeled after the standard library's sql and sql/driver packages, although the client API is completely different due to the different database models implemented by SQL and NoSQL databases such as CouchDB.

Installation

Install Kivik as you normally would for any Go package:

go get -u github.com/flimzy/kivik
go get -u github.com/go-kivik/couchdb

This will install the main Kivik package and the CouchDB database driver. See the list of Kivik database drivers for a complete list of available drivers.

Example Usage

Please consult the the package documentation for all available API methods, and a complete usage documentation. And for additional usage examples, consult the wiki.

package main

import (
    "context"
    "fmt"

    "github.com/flimzy/kivik"
    _ "github.com/go-kivik/couchdb" // The CouchDB driver
)

func main() {
    client, err := kivik.New(context.TODO(), "couch", "http://localhost:5984/")
    if err != nil {
        panic(err)
    }

    db, err := client.DB(context.TODO(), "animals")
    if err != nil {
        panic(err)
    }

    doc := map[string]interface{}{
        "_id":      "cow",
        "feet":     4,
        "greeting": "moo",
    }

    rev, err := db.Put(context.TODO(), "cow", doc)
    if err != nil {
        panic(err)
    }
    fmt.Printf("Cow inserted with revision %s\n", rev)
}

Frequently Asked Questions

Nobody has ever asked me any of these questions, so they're probably better called "Never Asked Questions" or possibly "Imagined Questions."

Why another CouchDB client API?

Read the design goals for the general design goals.

Specifically, I was motivated to write Kivik for a few reasons:

  1. I was unhappy with any of the existing CouchDB drivers for Go. The best one had a number of shortcomings:

    • It is no longer actively developed.
    • It doesn't have an open source license.
    • It doesn't support iterating over result sets, forcing one to load all results of a query into memory at once.
    • It doesn't support CouchDB 2.0 sequence IDs or MongoDB-style queries.
    • It doesn't natively support CookieAuth (it does allow a generic Auth method which could be used to do this, but I think it's appropriate to put directly in the library).
  2. I wanted a single client API that worked with both CouchDB and PouchDB. I had previously written go-pouchdb, a GopherJS wrapper around the PouchDB library with a public API modeled after fjl/go-couchdb, but I still wanted a unified driver infrastructure.

  3. I want an unambiguous, open source license. This software is released under the Apache 2.0 license. See the included LICENSE.md file for details.

  4. I wanted the ability to mock CouchDB connections for testing. This is possible with the sql / sql/driver approach by implementing a mock driver, but was not possible with any existing CouchDB client libraries. This library makes that possible for CouchDB apps, too.

  5. I wanted a simple, mock CouchDB server I could use for testing. It doesn't need to be efficient, or support all CouchDB servers, but it should be enough to test the basic functionality of a PouchDB app, for instance. Kivik aims to do this with the kivik serve command, in the near future.

  6. I wanted a toolkit that would make it easy to build a proxy to sit in front of CouchDB to handle custom authentication or other logic that CouchDB cannot support natively. Kivik aims to accomplish this in the future.

What are Kivik's requirements?

Kivik's test suite is automatically run on Linux and OSX for every pull request, but should work on all supported Go platforms.

Below are the compatibility targets for specific runtime and database versions. If you discover a bug affecting any of these supported environments, please let me know by submitting a bug report via GitHub.

  • Go Kivik 1.x aims for full compatibility with all stable releases of Go from 1.7.
  • CouchDB The Kivik 1.x CouchDB driver aims for compatibility with all stable releases of CouchDB from 1.6.1.
  • GopherJS GopherJS always requires the latest stable version of Go, so building Kivik with GopherJS has this same requirement.
  • PouchDB The Kivik 1.x PouchDB driver aims for compatibility with all stable releases of PouchDB from 6.0.0.

What is the development status?

Kivik comes with a complete client API client and backend drivers for CouchDB and PouchDB.

My next priorities are to work on fleshing out the Memory driver, which will make automated testing without a real CouchDB server easier. Then I will work on completing the 'serve' mode.

You can see a complete overview of the current status on the Compatibility chart

Why the name "Kivik"?

Kivik is a line of sofas (couches) from IKEA. And in the spirit of IKEA, and build-your-own furniture, Kivik aims to allow you to "build your own" CouchDB client, server, and proxy applications.

What license is Kivik released under?

This software is released under the terms of the Apache 2.0 license. See LICENCE.md, or read the full license.

# Packages

Package driver defines interfaces to be implemented by database drivers as used by package kivik.
Package errors provides convenience functions for Kivik drivers to report meaningful errors.

# Functions

New creates a new client object specified by its database driver name and a driver-specific data source name.
NewAttachment returns a new CouchDB attachment.
Reason returns the reason description for the error, or the error itself if none.
Register makes a database driver available by the provided name.
StatusCode returns the HTTP status code embedded in the error, or 500 (internal server error), if there was no specified status code.

# Constants

EndKeySuffix is a high Unicode character (0xfff0) useful for appending to an endkey argument, when doing a ranged search, as described here: http://couchdb.readthedocs.io/en/latest/ddocs/views/collation.html#string-ranges Example, to return all results with keys beginning with "foo": rows, err := db.Query(context.TODO(), "ddoc", "view", map[string]interface{}{ "startkey": "foo", "endkey": "foo" + kivik.EndKeySuffix, }).
KivikVendor is the vendor string reported by this library.
KivikVersion is the version of the Kivik library.
HTTP methods supported by CouchDB.
HTTP methods supported by CouchDB.
HTTP methods supported by CouchDB.
HTTP methods supported by CouchDB.
HTTP methods supported by CouchDB.
HTTP methods supported by CouchDB.
The possible values for the _replication_state field in _replicator documents plus a blank value for unstarted replications.
The possible values for the _replication_state field in _replicator documents plus a blank value for unstarted replications.
The possible values for the _replication_state field in _replicator documents plus a blank value for unstarted replications.
The possible values for the _replication_state field in _replicator documents plus a blank value for unstarted replications.
SessionCookieName is the name of the CouchDB session cookie.
HTTP response codes permitted by the CouchDB API.
StatusBadContentType is a misspelling of StatusUnsupportedMediaType.
HTTP response codes permitted by the CouchDB API.
StatusBadResponse indicates that the server responded with unrecognized data.
HTTP response codes permitted by the CouchDB API.
HTTP response codes permitted by the CouchDB API.
HTTP response codes permitted by the CouchDB API.
HTTP response codes permitted by the CouchDB API.
HTTP response codes permitted by the CouchDB API.
HTTP response codes permitted by the CouchDB API.
StatusIteratorUnusable indicates an improper use of an iterator, such as calling an iterator prematurely, or after it was closed.
HTTP response codes permitted by the CouchDB API.
StatusNetworkError represents an error that occurred outside of the HTTP transport, such as a problem contacting the remote server.
HTTP response codes permitted by the CouchDB API.
StatusNotImplemented is not returned by CouchDB proper.
HTTP response codes permitted by the CouchDB API.
HTTP response codes permitted by the CouchDB API.
HTTP response codes permitted by the CouchDB API.
HTTP response codes permitted by the CouchDB API.
HTTP response codes permitted by the CouchDB API.
StatusResourceNotAllowed is a misspelling of StatusMethodNotAllowed.
HTTP response codes permitted by the CouchDB API.
HTTP response codes permitted by the CouchDB API.
StatusUnknownError is used for unclassified errors generated by Kivik, generally caused by a programming error.
HTTP response codes permitted by the CouchDB API.
UserPrefix is the mandatory CouchDB user prefix.

# Structs

Attachment represents a file attachment on a CouchDB document.
BulkResults is an iterator over the results of a BulkDocs query.
Changes is an iterator over the database changes feed.
Client is a client connection handle to a CouchDB-like server.
ClusterConfig contains the cluster configuration for the database.
DB is a handle to a specific database.
DBStats contains database statistics..
DBUpdates provides access to database updates.
Index is a MonboDB-style index definition.
Members represents the members of a database security document.
QueryPlan is the query execution plan for a query, as returned by the Explain function.
Replication represents a CouchDB replication process.
ReplicationInfo represents a snapshot of the status of a replication.
Row is the result of calling Get for a single document.
Rows is an iterator over a a multi-value query.
Security represents a database security document.
Session represents an authentication session.
Version represents a server version response.

# Type aliases

Attachments is a collection of one or more file attachments.
MD5sum is a 128-bit MD5 checksum.
Options is a collection of options.
ReplicationState represents a replication's state.