leaf

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

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

Go to latest
Published: Sep 22, 2015 License: MIT Imports: 4 Imported by: 4

README

leaf

A small wrapper around BoltDB

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound is returned if a Keyspace did not contain the key
	ErrKeyNotFound = errors.New("Key does not exist")

	// ErrEmptyKeyList is returned if Keyspace.List() is called with no keys
	ErrEmptyKeyList = errors.New("Empty key list")
)

Functions

This section is empty.

Types

type BoltKeyspace

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

BoltKeyspace implements the Keyspace interface on top of a boltdb connection

func (*BoltKeyspace) Contains

func (b *BoltKeyspace) Contains(key string) (exists bool, err error)

Contains determines if a key already exists in the keyspace

func (*BoltKeyspace) Delete

func (b *BoltKeyspace) Delete(key string) error

Delete removes a key from the keyspace

func (*BoltKeyspace) ForEach

func (b *BoltKeyspace) ForEach(each ItemHandler) error

ForEach iterates over all the key value pairs in the keyspace

func (*BoltKeyspace) Get

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

Get returns the value for the given key

func (*BoltKeyspace) GetName

func (b *BoltKeyspace) GetName() string

GetName returns the name of the keyspace

func (*BoltKeyspace) Insert

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

Insert adds a key value pair to the databaes

func (*BoltKeyspace) List

func (b *BoltKeyspace) List(keys []string, callback func(k, v []byte)) error

List iterates over the given keys and calls the ItemHandler with each key value pair

func (*BoltKeyspace) ReadTx

func (b *BoltKeyspace) ReadTx(callback func(*bolt.Bucket)) error

ReadTx allows for more complex read operations on the keyspace

func (*BoltKeyspace) Size

func (b *BoltKeyspace) Size() (value int64)

Size returns the number of keys in the keyspace

func (*BoltKeyspace) Update

func (b *BoltKeyspace) Update(key string, value []byte) error

Update overwrites an existing value

func (*BoltKeyspace) WriteTx

func (b *BoltKeyspace) WriteTx(callback func(*bolt.Bucket)) error

WriteTx allows for more complex write operations on the keyspace

type DB

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

DB wraps a BoltDB connection

func (*DB) Close

func (l *DB) Close() error

Close closes the database connection

func (*DB) DeleteKeyspace

func (l *DB) DeleteKeyspace(name string) error

DeleteKeyspace removes a keyspace from the database

func (*DB) GetOrCreateKeyspace

func (l *DB) GetOrCreateKeyspace(name string) (ks Keyspace, err error)

GetOrCreateKeyspace returns a Keyspace implementation for the underlying BoltDB instance.

type ItemHandler

type ItemHandler func(k, v []byte) error

ItemHandler represents a callback for processing a single key-value pair.

type KeyValueDatabase

type KeyValueDatabase interface {

	// GetOrCreatKeyspace returns a new keyspace instance from the database, creating it if it doesn't exist
	GetOrCreateKeyspace(string) (Keyspace, error)

	// DeleteKeyspace removes a keyspace from the database
	DeleteKeyspace(string) error

	// Close closes the database connection
	Close() error
}

KeyValueDatabase is used as an interface for accessing multiple keyspaces.

func NewLeaf

func NewLeaf(file string) (KeyValueDatabase, error)

NewLeaf creates a connection to a BoltDB file

type Keyspace

type Keyspace interface {

	// GetName returns the name of the keyspace
	GetName() string

	// List finds all the keys listed and calls the function provided with the key value pairs
	List([]string, func(k, v []byte)) error

	// Insert adds a key value to the keyspace
	Insert(string, []byte) error

	// Get returns a value with the associated key and returns an error if the key does not exist
	Get(string) ([]byte, error)

	// Update overrides the existing value associated with the given key
	Update(string, []byte) error

	// Delete removes a key from the keyspace
	Delete(string) error

	// Size returns the number of items in the keyspace
	Size() int64

	// ForEach iterates over all the keys in the keyspace
	ForEach(ItemHandler) error

	// Contains determines if the given key exists in the keyspace
	Contains(string) (bool, error)

	// ReadTx allows for more complicated read operations on a particular key, such as reading nested values.
	ReadTx(func(*bolt.Bucket)) error

	// WriteTx allows for more complicated write operations on a particular key, such as writing nested values.
	WriteTx(func(*bolt.Bucket)) error
}

Keyspace is an interface for Database keyspaces. It is used as a wrapper for database actions.

Jump to

Keyboard shortcuts

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