boltutils

package module
v0.0.0-...-3acb389 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2017 License: MIT Imports: 8 Imported by: 5

README

Bolt utils Build Status Go Report Card Coverage Status GoDoc

Bolt db wrapper for facilitating the use it low-level API.

Usage

import (
  "github.com/zhuharev/boltutils"
)

...

db, _ := boltutils.Open("path/to/db.bolt", 0666, nil)
db.Put([]byte("key"), []byte("value"))
value, _ := db.Get([]byte("key"))
// value = []byte("value")

gzip in the box

db.PutGzip([]byte("key"), []byte("value"))
value, _ := db.GetGzipped([]byte("key"))
// value = []byte("value")

json support

db.PutJSON(anyStruct)
err = db.GetJSON([]byte("bucket"), []byte("key"), &anyStruct)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound not found error
	ErrNotFound = fmt.Errorf("not found")
	// ErrBreak break's iterator
	ErrBreak = fmt.Errorf("break")
)

Functions

func Compression

func Compression(ct CompressorType) func(db *DB) error

func CreateBucket

func CreateBucket(db *bolt.DB, bucketName []byte) error

CreateBucket create bucket if not exists

func CreateBucketPath

func CreateBucketPath(db *bolt.DB, bucketPath [][]byte) error

func Get

func Get(db *bolt.DB, bucketName, key []byte) ([]byte, error)

Get value from database

func GetPath

func GetPath(db *bolt.DB, bucketNames [][]byte, key []byte) ([]byte, error)

GetPath value from database bucket/subbucket/.../valuebucket

func Iterate

func Iterate(db *bolt.DB, bucketName []byte, fn func(k, v []byte) error, compressors ...Compressor) error

Iterate over database

func IteratePrefix

func IteratePrefix(db *bolt.DB, bucketName, prefix []byte, fn func(k, v []byte) error) error

IteratePrefix over database

func Put

func Put(db *bolt.DB, bucketName interface{}, key, value []byte) error

Put value into database

func PutPath

func PutPath(db *bolt.DB, bucketNames [][]byte, key, value []byte) error

PutPath value into database

Types

type Compressor

type Compressor interface {
	Compress(data []byte) ([]byte, error)
	Decompress(data []byte) ([]byte, error)
}

type CompressorType

type CompressorType int
const (
	NoopCompressor CompressorType = iota
	GzipCompressor
	Lz4Compressor
)

type DB

type DB struct {
	*bolt.DB
	Compressor Compressor
}

DB wrapper for bolt.DB

func New

func New(opts ...Opt) (db *DB, err error)

New return pointer of DB

func (*DB) CreateBucket

func (db *DB) CreateBucket(bucketName []byte) error

CreateBucket create buckt if it not exists

func (*DB) CreateBucketPath

func (db *DB) CreateBucketPath(bucketPath [][]byte) error

func (*DB) Get

func (db *DB) Get(bucketName, key []byte) ([]byte, error)

Get value from db

func (*DB) GetJSON

func (db *DB) GetJSON(bucketName, key []byte, v interface{}) (err error)

func (*DB) GetPath

func (db *DB) GetPath(bucketName [][]byte, key []byte) ([]byte, error)

GetPath value from db

func (*DB) Iterate

func (db *DB) Iterate(bucketName []byte, fn func(k, v []byte) error) error

Iterate over db

func (*DB) IterateGzipped

func (db *DB) IterateGzipped(bucketName []byte, fn func(k, v []byte) error) error

func (*DB) IteratePrefix

func (db *DB) IteratePrefix(bucketName, prefix []byte, fn func(k, v []byte) error) error

IteratePrefix over db

func (*DB) Put

func (db *DB) Put(bucketName interface{}, key, value []byte) (err error)

Put value into db

func (*DB) PutJSON

func (db *DB) PutJSON(bucketName, key []byte, v interface{}) error

func (*DB) PutPath

func (db *DB) PutPath(bucketName [][]byte, key, value []byte) error

PutPath value into db

type Opt

type Opt func(db *DB) error

func BoltDB

func BoltDB(bdb *bolt.DB) Opt

func Open

func Open(path string, mode os.FileMode, options *bolt.Options) Opt

Open open database file and return pointer of DB

func OpenPath

func OpenPath(path string) Opt

OpenPath shortland for Open with single arg

Jump to

Keyboard shortcuts

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