Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/pupizoid/gocouch

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/pupizoid/gocouch

  • v0.0.0-20161108122855-7689f73cca8d
  • Source
  • Go
  • Socket score

Version published
Created
Source

Build Status Go Report Card GoDoc

###Connecting to server:

defaultTimeout := time.Second * 10
conn, err := gocouch.Connect("127.0.0.1", 5984, nil, defaultTimeout)

// With credentials
auth := gocouch.BasicAuth{"admin", "pass"}
conn, err := gocouch.Connect("127.0.0.1", 5984, auth, defaultTimeout)

###Database operations: Get existing database or create new one:

db, err := conn.MustGetDatabase("some_db", nil)

Non-nil Auth passed to this method has higher priority, so it will owerride previously used on Connect. By default this method use Auth object provided when connection was created.

Get all existing databases:

list, err := conn.GetAllDBs()

Fetch new database related action on CouchDB instance:

var events map[string]interface{}
err := conn.GetDBEvent(&events, nil)

This request will block workflow until any event happens or default timeout (60 sec) will be exceeded. If you try to specify custom operation timeout note that it accepts milliseconds. Also it's safe to use in goroutine.

If you want to fetch many events, you can use GetDBEventChan:

eventChan, err := conn.GetDBEventChan()
// don't forget to close channel to release connection resourses
defer close(eventChan)

###Basic CRUD actions with a single document:

package main

import (
	"github.com/pupizoid/gocouch"
	"time"
)

func main() {
	server, _ := gocouch.Connect("127.0.0.1", 5984, nil, time.Second * 10)

	type Doc struct {
		Field string `json:"field"`
		// Note: struct data will override `id` param in database methods,
		// to avoid conflicts struct fields representing document's
		// `_id` & `_rev` should always contain json tag `omitempty`
		Rev   string `json:"_rev,omitempty"`
		ID    string `json:"_id,omitempty"`
	}

	var document1, document2 Doc

	db, _ := server.MustGetDatabase("test_db", nil)

	document1.Field = "value"
  
    // Create document with specified id (also accepts map as a document)
	db.Put("test_id", &document1)
	// Get document by id
	db.Get("test_id", &document2, nil)
	// Delete document's revision
	db.Del(document2.ID, document2.Rev)

}

###Bulk operations:

##TODO:

  • Server API
  • Database API
  • Document API
  • Authentication
  • Design Docs & Views
  • Attachments
  • Coverage > 90%

FAQs

Package last updated on 08 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc