gocouchDB

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

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

Go to latest
Published: Dec 27, 2015 License: MIT Imports: 7 Imported by: 1

README

This project is in developing...

Yet another CouchDB GO Client

0.1 is for core API

Quick start

// Client is your friend
// Use Client everywhere you want :)

import (
    "github.com/GuoJing/gocouchDB"
)

dsn := "http://localhost:5984"
client := gocouchDB.NewClientByDSN(dsn)

db, err := client.GetDatabase("duidui")

if err != nil {}

doc, err := db.GetDocument("test")

body := map[string]interface{} {
    "title" : "Haha223334444",
    "body"  : "Not at all",
}

doc.Update(body)

// Or
// doc.Delete()

Transport

//interface ITransport! <- you can do it yourself
transport := NewTransport(dsn)

client := gocouchDB.NewClientByTransport(transport)

Visit without Client

transport := NewTransport(dsn)
db := NewDatabase(dbName, transport)
doc, err := db.GetDocument(Name)

doc = NewDocument(dbName, Name, transport)
doc.Delete()

Auth

client := gocouchDB.NewClientByDSN(dsn)
client.SetAuth(Username, Password)
client.GetDatabase("duidui")
// ...

// or

transport := NewTransport(dsn)
db := NewDatabase(dbName, transport)
db.SetAuth(Username, Password)
db.GetDocument("doc")
// ...

Replicate

task := new(gocouchDB.ReplicateTask)
task.Continuous = false
task.CreateTarget = true
task.Source = "duidui"
task.Target = "duidui_backup"

ret, err := client.Replicate(task)

do function

// You could do anything with do
// this is ClientBase
// you can do that in every Class
// like Database, Document...
// Here we call this cl
// if we need a couchdb interface like:
// dsn/_replicate?param1=value1

body = map[string]interface{} {
    "source": "source_db",
    "target": "target_db",
}

params = map[string]string {
    "param1": "value1"
}

cl.do(POST, "_replicate", body, params)

// you could see Compact in Database class
// everything is using do function (but _all_dbs)

Documentation

Index

Constants

View Source
const (
	GET    = "GET"
	POST   = "POST"
	DELETE = "DELETE"
	PUT    = "PUT"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ClientBase
}

func NewClientByDSN

func NewClientByDSN(dsn string) *Client

func NewClientByTransport

func NewClientByTransport(transport ITransport) *Client

func (*Client) CreateDatabase

func (cl *Client) CreateDatabase(dbName string) (j map[string]interface{}, err error)

create database with dbName

func (*Client) GetDatabase

func (cl *Client) GetDatabase(dbName string) (d *Database, err error)

get database

func (*Client) ListAllDatabases

func (cl *Client) ListAllDatabases() (j []string, err error)

this is a tricky function couchdb only this interface return a list not a key-value map json

func (*Client) Replicate

func (cl *Client) Replicate(task *ReplicateTask) (j map[string]interface{}, err error)

replicate database

func (*Client) ServerInfo

func (cl *Client) ServerInfo() (j map[string]interface{}, err error)

get server info

type ClientBase

type ClientBase struct {
	Headers  map[string]string
	Username string
	Password string
	// contains filtered or unexported fields
}

func (*ClientBase) ClearHeaders

func (cl *ClientBase) ClearHeaders()

func (*ClientBase) SetAuth

func (cl *ClientBase) SetAuth(username, password string)

set basic auth

func (*ClientBase) SetHeaders

func (cl *ClientBase) SetHeaders(headers map[string]string)

type CouchdbError

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

func (CouchdbError) Error

func (e CouchdbError) Error() string

type Database

type Database struct {
	ClientBase
	Name string
}

func NewDatabase

func NewDatabase(dbName string, transport ITransport) *Database

func (*Database) Compact

func (cl *Database) Compact() (j map[string]interface{}, err error)

compact database

func (*Database) CompactDesignDoc

func (cl *Database) CompactDesignDoc(designDoc string) (j map[string]interface{}, err error)

compact design doc

func (*Database) CreateDocument

func (cl *Database) CreateDocument(key string, body map[string]interface{}) (j map[string]interface{}, err error)

create document

func (*Database) Delete

func (cl *Database) Delete() (j map[string]interface{}, err error)

delete a database

func (*Database) DeleteBulkDocuments

func (cl *Database) DeleteBulkDocuments(body map[string]interface{}) (j map[string]interface{}, err error)

func (*Database) EnsureFullCommit

func (cl *Database) EnsureFullCommit() (j map[string]interface{}, err error)

ensure full commit

func (*Database) GetDocument

func (cl *Database) GetDocument(key string) (d *Document, err error)

get document

func (*Database) GetDocuments

func (cl *Database) GetDocuments(params map[string]string) (j map[string]interface{}, err error)

get all docs http://docs.couchdb.org/en/1.6.1/api/database/bulk-api.html#db-bulk-docs

func (*Database) GetDocumentsByKeys

func (cl *Database) GetDocumentsByKeys(body map[string]interface{}) (j map[string]interface{}, err error)

get docs by keys

func (*Database) GetInfo

func (cl *Database) GetInfo() (j map[string]interface{}, err error)

show database info

func (*Database) GetSecurity

func (cl *Database) GetSecurity() (j map[string]interface{}, err error)

get db security

func (*Database) InsertBulkDocuments

func (cl *Database) InsertBulkDocuments(body map[string]interface{}) (j map[string]interface{}, err error)

func (*Database) SetSecurity

func (cl *Database) SetSecurity(body map[string]interface{}) (j map[string]interface{}, err error)

set db security

func (*Database) UpdateBulkDocuments

func (cl *Database) UpdateBulkDocuments(body map[string]interface{}) (j map[string]interface{}, err error)

update/insert/delete bulk documents

func (*Database) ViewCleanUp

func (cl *Database) ViewCleanUp() (j map[string]interface{}, err error)

clean db view

type Document

type Document struct {
	Name         string
	DatabaseName string
	ClientBase
}

func NewDocument

func NewDocument(dbName, docName string, transport ITransport) *Document

func (*Document) CreateAttachment

func (cl *Document) CreateAttachment(attname string, data io.Reader, headers map[string]string) (j map[string]interface{}, err error)

create attachement

func (*Document) CreateAttachmentByReversion

func (cl *Document) CreateAttachmentByReversion(attname, rev string, data io.Reader, headers map[string]string) (j map[string]interface{}, err error)

create attachment

func (*Document) Delete

func (cl *Document) Delete() (j map[string]interface{}, err error)

delete document by update _deleted

func (*Document) DeleteAttachment

func (cl *Document) DeleteAttachment(attname string) (j map[string]interface{}, err error)

delete attachment

func (*Document) DeleteAttachmentByReversion

func (cl *Document) DeleteAttachmentByReversion(attname, rev string) (j map[string]interface{}, err error)

delete attachment

func (*Document) GetAttachment

func (cl *Document) GetAttachment(attname string) (j map[string]interface{}, err error)

get attachment

func (*Document) GetAttachmentByReversion

func (cl *Document) GetAttachmentByReversion(attname, rev string) (j map[string]interface{}, err error)

get attachment

func (*Document) GetInfo

func (cl *Document) GetInfo() (j map[string]interface{}, err error)

get info of the document

func (*Document) GetInfoByReversion

func (cl *Document) GetInfoByReversion(rev string) (j map[string]interface{}, err error)

get info by reversion

func (*Document) GetReversion

func (cl *Document) GetReversion() (r string, err error)

get reversion of the document

func (*Document) Leaf

func (cl *Document) Leaf() (j map[string]interface{}, err error)

get leaf node of the couchdb B-tree

func (*Document) Update

func (cl *Document) Update(body map[string]interface{}) (j map[string]interface{}, err error)

update document

type ICache

type ICache interface {
	Get(key string, defaultValue interface{}) (value interface{})
	Set(key string, value interface{}) (ret bool)
	Delete(key string) (ret bool)
}

type ITransport

type ITransport interface {
	// contains filtered or unexported methods
}

type MemCache

type MemCache struct {
	Hash map[string]interface{}
}

func NewMemCache

func NewMemCache() *MemCache

func (*MemCache) Delete

func (cl *MemCache) Delete(key string) (ret bool)

func (*MemCache) Get

func (cl *MemCache) Get(key string, defaultValue interface{}) (value interface{})

func (*MemCache) Set

func (cl *MemCache) Set(key string, value interface{}) (ret bool)

type ReplicateTask

type ReplicateTask struct {
	Source       string
	Target       string
	Proxy        string
	Continuous   bool
	CreateTarget bool
	Cancel       bool
	DocumentIDs  []string
}

type Transport

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

func NewTransport

func NewTransport(dsn string) *Transport

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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