boltstore

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: MIT Imports: 4 Imported by: 0

README ΒΆ

boltstore πŸͺ

GoDoc

boltstore is a Go-library for a simple thread-safe in-memory key-store with persistent BoltDB backend.

Usage

First, install the library using:

go get -u -v github.com/schollz/boltstore

Then you can add it to your program. Check out the examples, or see below for basic usage:

ks := boltstore.Open("mystore.db")

// set a key to any object you want
type Human struct {
  Name   string
  Height float64
}
err := ks.Set("human:1", Human{"Dante", 5.4})
if err != nil {
  panic(err)
}

// get the data back via an interface
var human Human
err = ks2.Get("human:1", &human)
if err != nil {
  panic(err) // returns error if key doesn't exist
}
fmt.Println(human.Name) // Prints 'Dante'

Benchmark

$ go test -bench=.
goos: linux
goarch: amd64
pkg: github.com/schollz/boltstore
BenchmarkGet-4            500000              2474 ns/op
BenchmarkSet-4               300           7375338 ns/op

License

MIT

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type BoltStore ΒΆ

type BoltStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

BoltStore is the basic store object.

func Open ΒΆ

func Open(filename string) (s *BoltStore, err error)

Open will load a BoltStore from a file.

func (*BoltStore) Delete ΒΆ

func (s *BoltStore) Delete(key string) error

Delete removes a key from the store.

func (*BoltStore) Get ΒΆ

func (s *BoltStore) Get(key string, v interface{}) (err error)

Get will return the value associated with a key.

func (*BoltStore) GetAll ΒΆ added in v1.1.0

func (s *BoltStore) GetAll(v interface{}, keyvalue func(key string) error) (err error)

GetAll will iterate over everything and return things that have the same type as the interface passed

func (*BoltStore) Keys ΒΆ

func (s *BoltStore) Keys() []string

Keys returns all the keys currently in map

func (*BoltStore) Set ΒΆ

func (s *BoltStore) Set(key string, value interface{}) error

Set saves a value at the given key.

type NoSuchKeyError ΒΆ

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

NoSuchKeyError is thrown when calling Get with invalid key

func (NoSuchKeyError) Error ΒΆ

func (err NoSuchKeyError) Error() string

Jump to

Keyboard shortcuts

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