bbolt

package module
v0.0.0-...-9e942d2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: MIT Imports: 4 Imported by: 0

README

BBolt wrapper

Build Status

This package define utilities functions for Bolt.

Install package

go get github.com/lorenzodisidoro/bbolt

Usage

Import bbolt package in your GO file

import "github.com/lorenzodisidoro/bbolt"

it define BBolt and KeyValue types

// BBolt define instance
type BBolt struct {
	Path       string
	BucketName []byte
	Storage    *bolt.DB
}

// KeyValue define functions response
type KeyValue struct {
	Key   []byte
	Value []byte
}
New key-value store
dir, _ := os.Getwd()
dbPath := dir + "/test.db"

// new BBolt instance
testBucket, err := bbolt.NewBBolt(dbPath, []byte("test_bucket"))
if err != nil {
    log.Fatal(err)
}
Add new key-value or update
// put key/value into 'test_bucket'
testKey := []byte("love")
err = testBucket.Update(testKey, []byte("bitcoin"))
if err != nil {
    log.Fatal(err)
}
Get by key
// get value by key
keyValue, err := testBucket.GetBy(testKey)
if err != nil {
    log.Fatal(err)
}

fmt.Printf("I love %v", string(keyValue.Value))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BBolt

type BBolt struct {
	Path       string
	BucketName []byte
	Storage    *bolt.DB
}

BBolt define bbolt instance

func NewBBolt

func NewBBolt(path string, bucketName []byte) (*BBolt, error)

NewBBolt function set up bbolt local storage @param path <string>: creates storage at the given path @param bucketName <[]byte> @return (BoltDatabase, error)

func (*BBolt) GetAll

func (bb *BBolt) GetAll() ([]*KeyValue, error)

GetAll retrieves all bucket's key/value @return ([]string, error)

func (*BBolt) GetBy

func (bb *BBolt) GetBy(key []byte) (*KeyValue, error)

GetBy retrieve data by key @param key <[]byte> @return error

func (*BBolt) Update

func (bb *BBolt) Update(key []byte, value []byte) error

Update create or update key parameter @param key <[]byte> @param value <[]byte> @return error

type KeyValue

type KeyValue struct {
	Key   []byte
	Value []byte
}

KeyValue define response

Jump to

Keyboard shortcuts

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