db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyKey = errors.New("key cannot be empty")

ErrEmptyKey is returned when key is empty.

View Source
var ErrIndexOutOfRange = errors.New("iterator index out of range")

ErrIndexOutOfRange is returned when the iterator index is not in a valid range.

View Source
var ErrNotFound = errors.New("key not found")

ErrNotFound is returned when there is no value associated with a key.

Functions

This section is empty.

Types

type DB

type DB interface {
	// Insert a value associated with a key. This will override any existing
	// value associated with the key.
	Insert(key string, value []byte) error

	// Get the value associated with the key. If no value is associated with the
	// key, then an `ErrNotFound` error will be returned.
	Get(key string) ([]byte, error)

	// Delete the value associated with the key.
	Delete(key string) error
}

DB for storing key-value tuples. The key must be a string and the value must be a byte slice.

type Iterable

type Iterable interface {
	DB

	// Size returns the number of key-value tuples in the Iterable DB.
	Size() (int, error)

	// Iterator returns an Iterator which can be used to iterate through all
	// key-value tuples in the IterableDB.
	Iterator() Iterator
}

Iterable is a DB that can iterate over its key-value tuples.

type Iterator

type Iterator interface {

	// Next will progress the iterator to the next element. If there are more
	// elements in the iterator, then it will return true, otherwise it will
	// return false.
	Next() bool

	// Key of the current key-value tuple. Calling Key() without calling
	// Next() or no next item in the iter will result in `ErrIndexOutOfRange`
	Key() (string, error)

	// Value of the current key-value tuple. Calling Value() without calling
	// Next() or no next item in the iter will result in `ErrIndexOutOfRange`
	Value() ([]byte, error)
}

Iterator is used to iterate through the data in the store.

Jump to

Keyboard shortcuts

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