mbuckets

package module
v0.0.0-...-e8cfc92 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2018 License: MIT Imports: 5 Imported by: 0

README

mbuckets

GoDoc Build Status Coverage Status

A simple wrapper over BoltDB that allows easy operations on multi level (nested) buckets.

Overview

mbuckets is heavily inspired by Buckets.

mbuckets originated from a need to store data under heirarchial paths.

Installation

go get -u github.com/abhigupta912/mbuckets

Usage

See mbuckets_test.go for examples.

Documentation

Overview

Package mbuckets provides a thin wrapper over Bolt DB. It allows easy operations on multi-level (nested) buckets.

See https://github.com/boltdb/bolt for Bolt DB.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	DB *DB

	// Complete hierarchial name of the Bucket
	Name []byte

	// The Bucket Name separator
	Separator []byte
}

Bucket represents a logical entity used to access a bolt.Bucket inside a DB

func (*Bucket) CreateBucket

func (b *Bucket) CreateBucket() error

CreateBucket cretes the bolt.Bucket specified by this Bucket

func (*Bucket) Delete

func (b *Bucket) Delete(key []byte) error

Delete removes the given key from the bolt.Bucket specified by this Bucket

func (*Bucket) DeleteBucket

func (b *Bucket) DeleteBucket() error

DeleteBucket deletes the bolt.Bucket specified by this Bucket

func (*Bucket) DeleteString

func (b *Bucket) DeleteString(key string) error

DeleteString is a convenience wrapper over Delete for string key

func (*Bucket) Get

func (b *Bucket) Get(key []byte) (value []byte, err error)

Get retrieves the value for given a key from the bolt.Bucket specified by this Bucket

func (*Bucket) GetAll

func (b *Bucket) GetAll() ([]Item, error)

GetAll retrieves all the key/value pairs from the bolt.Bucket specified by this Bucket

func (*Bucket) GetAllBucketNames

func (b *Bucket) GetAllBucketNames() ([][]byte, error)

GetAllBucketNames recursively finds and returns all the bolt.Bucket names under the bolt.Bucket specified by this Bucket

func (*Bucket) GetAllString

func (b *Bucket) GetAllString() (map[string]string, error)

GetAllString is a convenience method to GetAll string key value pairs

func (*Bucket) GetPrefix

func (b *Bucket) GetPrefix(prefix []byte) ([]Item, error)

GetPrefix retrieves all the key/value pairs from the bolt.Bucket specified by this Bucket with the given prefix

func (*Bucket) GetPrefixString

func (b *Bucket) GetPrefixString(prefix string) (map[string]string, error)

GetPrefixString is a convenience method to GetPrefix for string key value pairs

func (*Bucket) GetRange

func (b *Bucket) GetRange(min, max []byte) ([]Item, error)

GetRange retrieves all the key/value pairs from the bolt.Bucket specified by this Bucket within the given range

func (*Bucket) GetRangeString

func (b *Bucket) GetRangeString(min, max string) (map[string]string, error)

GetRangeString is a convenience method to GetRange for string key value pairs

func (*Bucket) GetRootBucketNames

func (b *Bucket) GetRootBucketNames() ([][]byte, error)

GetRootBucketNames returns all the top level bolt.Bucket names under the bolt.Bucket specified by this Bucket

func (*Bucket) GetString

func (b *Bucket) GetString(key string) (value string, err error)

GetString is a convenience wrapper over Get for string key value pair

func (*Bucket) Insert

func (b *Bucket) Insert(key, value []byte) error

Insert puts a single key/value pair in the bolt.Bucket specified by this Bucket

func (*Bucket) InsertAll

func (b *Bucket) InsertAll(items []Item) error

InsertAll puts multiple key/value pairs in the bolt.Bucket specified by this Bucket

func (*Bucket) InsertAllString

func (b *Bucket) InsertAllString(items map[string]string) error

InsertAllString is a convenience method to Insert string key value pairs

func (*Bucket) InsertString

func (b *Bucket) InsertString(key, value string) error

InsertString is a convenience wrapper over Insert for string key value pair

func (*Bucket) Map

func (b *Bucket) Map(fn func([]byte, []byte) error) error

Map performs a view operation specified by function `fn` on all key value pairs in this Bucket

func (*Bucket) MapPrefix

func (b *Bucket) MapPrefix(prefix []byte, fn func([]byte, []byte) error) error

MapPrefix performs a view operation specified by function `fn` on all key value pairs in this Bucket with the given prefix

func (*Bucket) MapRange

func (b *Bucket) MapRange(min, max []byte, fn func([]byte, []byte) error) error

MapRange performs a view operation specified by function `fn` on all key value pairs in this Bucket within the given range

func (*Bucket) Update

func (b *Bucket) Update(fn func(*bolt.Bucket, *bolt.Tx) error) error

Update performs an update operation specified by function `fn` on this Bucket

func (*Bucket) View

func (b *Bucket) View(fn func(*bolt.Bucket, *bolt.Tx) error) error

View performs a view operation specified by function `fn` on this Bucket

func (*Bucket) WithSeparator

func (b *Bucket) WithSeparator(separator []byte) *Bucket

WithSeparator overrides the separator for this Bucket with the given separator and returns a pointer to this Bucket.

The name of this Bucket and all Buckets under it must be separated by the given custom separator. Note that it is an error to mix different separators and can lead to unexpected behavior.

type DB

type DB struct {
	*bolt.DB
}

DB embeds a bolt.DB

func Open

func Open(path string) (*DB, error)

Open creates/opens a bolt.DB at specified path, and returns a DB enclosing the same

func OpenWith

func OpenWith(path string, mode os.FileMode, options *bolt.Options) (*DB, error)

OpenWith creates/opens a bolt.DB at specified path with given permissions and options, and returns a DB enclosing the same

func (*DB) Bucket

func (db *DB) Bucket(name []byte) *Bucket

Bucket returns a pointer to a Bucket in this DB

func (*DB) BucketString

func (db *DB) BucketString(name string) *Bucket

BucketString is a convenience wrapper over Bucket for string name

func (*DB) Close

func (db *DB) Close() error

Close closes the embedded bolt.DB

func (*DB) GetAllBucketNames

func (db *DB) GetAllBucketNames() ([][]byte, error)

GetAllBucketNames recursively finds and returns all the bolt.Bucket names in this DB

func (*DB) GetAllBucketNamesWithSeparator

func (db *DB) GetAllBucketNamesWithSeparator(separator []byte) ([][]byte, error)

GetAllBucketNamesWithSeparator recursively finds and returns all the bolt.Bucket names in this DB using specified separator

func (*DB) GetRootBucketNames

func (db *DB) GetRootBucketNames() ([][]byte, error)

GetRootBucketNames returns all the top level bolt.Bucket names in this DB

func (*DB) Map

func (db *DB) Map(fn func([]byte, *bolt.Bucket) error) error

Map applies read only function `fn` on all the top level buckets in this DB

type Item

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

Item represents a holder for a key value pair

Jump to

Keyboard shortcuts

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