Home

Awesome

Go Report Card

boltdb-boilerplate

boltdb-boilerplate is a simple & stupid boilerplate project wrapping around boltdb, and aim to make simple calls as one-liners.

Methods Summary

Usage Demo

// import
import "github.com/bobintornado/boltdb-boilerplate"

// Init
buckets := []string{"ownerBucket", "sensors"}

err := boltdbboilerplate.InitBolt("./database.boltdb", buckets)
if err != nil {
  log.Fatal("Can't init boltDB")
}

// Put
err = boltdbboilerplate.Put([]byte("ownerBucket"), []byte("ownerKey"), []byte("username"))

// Get owner 
value := boltdbboilerplate.Get([]byte("ownerBucket"), []byte("ownerKey"))

// Delete
err = boltdbboilerplate.Delete([]byte("ownerBucket"), []byte("ownerKey"))

// Insert two key/value
err = boltdbboilerplate.Put([]byte("sensors"), []byte("key1"), []byte("value1"))
err = boltdbboilerplate.Put([]byte("sensors"), []byte("key2"), []byte("value2"))

// Get all keys
keys := boltdbboilerplate.GetAllKeys([]byte("sensors"))
// keys = [key1, key2]

// Get all key/value pairs
pairs := boltdbboilerplate.GetAllKeyValues([]byte("sensors"))
// pairs = [{Key:key1, Value:value1}, {Key: key2, Value:value2}]

// Close
boltdbboilerplate.Close()

Docs

GoDoc