boltdb-boilerplate is a simple & stupid boilerplate project wrapping around boltdb, and aim to make simple calls as one-liners.
InitBolt
: Init the databaseClose
: Close the databaseGet
: Retrieve a value by keyPut
: Put a key/value pair into a bucketDelete
: Delete a key/value pair from a bucketGetAllKeys
: Get all keys from a bucket in[][]byte
fromatGetAllKeyValues
: Get all key/value pairs from a bucket in[]BoltPair
fromat
// 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()