go-kivik / kivik

Common interface to CouchDB or CouchDB-like databases for Go and GopherJS
Other
316 stars 44 forks source link
couchdb database go gopherjs-bindings nosql pouchdb

Build Status Codecov Go Report Card Go Reference Website

Kivik

Package kivik provides a common 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.

Versions

You are browsing the current stable branch of Kivik, v4. If you are upgrading from the previous stable version, v3, read the list of breaking changes.

Example configuration for common dependency managers follow.

Go Modules

Kivik 3.x and later supports Go modules, which is the recommended way to use it for Go version 1.11 or newer. Kivik 4.x only supports Go 1.17 and later. If your project is already using Go modules, simply fetch the desired version:

go get github.com/go-kivik/kivik/v4

Installation

Install Kivik as you normally would for any Go package:

go get -u github.com/go-kivik/kivik/v4

This will install the main Kivik package and the CouchDB database driver. Three officially supported drivers are shipped with this Go module:

In addition, there are partial/experimental drivers available:

CLI

Consult the CLI README for full details on the kivik CLI tool.

Example Usage

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

package main

import (
    "context"
    "fmt"

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

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

    db := client.DB("animals")

    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?

I had a number of specific design goals when creating this package:

What are Kivik's requirements?

Kivik's test suite is automatically run on Linux for every pull request, but should work on all supported Go architectures. If you find it not working for your OS/architecture, please submit a bug report.

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.

What is the development status?

Kivik 4.x is stable, and suitable for production use.

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?

Kivik is Copyright 2017-2023 by the Kivik contributors, and is released under the terms of the Apache 2.0 license. See LICENCE for the full text of the license.

Changes from 3.x to 4.x

This is a partial list of breaking changes between 3.x and 4.x

CouchDB specific changes

New features and additions

What projects currently use Kivik?

If your project uses Kivik, and you'd like to be added to this list, create an issue or submit a pull request.