Documentation ¶
Index ¶
- func EncodeKeyPart(v interface{}) []byte
- func Exists(key []byte, keyExists *bool) func(storage.Reader) error
- func FindHighestAtOrBelow(prefix []byte, height uint64, entity interface{}) func(storage.Reader) error
- func FindHighestAtOrBelowByPrefix(r storage.Reader, prefix []byte, height uint64, entity interface{}) (errToReturn error)
- func Iterate(startPrefix []byte, endPrefix []byte, check func(key []byte) error) func(storage.Reader) error
- func IterateKeys(r storage.Reader, startPrefix []byte, endPrefix []byte, iterFunc IterationFunc, ...) (errToReturn error)
- func IterateKeysByPrefixRange(r storage.Reader, startPrefix []byte, endPrefix []byte, ...) error
- func KeyExists(r storage.Reader, key []byte) (exist bool, errToReturn error)
- func KeyPartToBytes(v interface{}) []byte
- func MakePrefix(code byte, keys ...interface{}) []byte
- func Remove(key []byte) func(storage.Writer) error
- func RemoveByKey(w storage.Writer, key []byte) error
- func RemoveByKeyPrefix(reader storage.Reader, w storage.Writer, key []byte) error
- func RemoveByKeyRange(reader storage.Reader, w storage.Writer, startPrefix []byte, endPrefix []byte) error
- func RemoveByPrefix(reader storage.Reader, key []byte) func(storage.Writer) error
- func RemoveByRange(reader storage.Reader, startPrefix []byte, endPrefix []byte) func(storage.Writer) error
- func Retrieve(key []byte, entity interface{}) func(storage.Reader) error
- func RetrieveByKey(r storage.Reader, key []byte, entity interface{}) (errToReturn error)
- func Traverse(prefix []byte, iterFunc IterationFunc, opt storage.IteratorOption) func(storage.Reader) error
- func TraverseByPrefix(r storage.Reader, prefix []byte, iterFunc IterationFunc, ...) error
- func Upsert(key []byte, val interface{}) func(storage.Writer) error
- func UpsertByKey(w storage.Writer, key []byte, val interface{}) error
- type Callbacks
- type CheckFunc
- type CreateFunc
- type HandleFunc
- type IterationFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeKeyPart ¶
func EncodeKeyPart(v interface{}) []byte
EncodeKeyPart encodes a value to be used as a part of a key to be stored in storage.
func FindHighestAtOrBelow ¶
func FindHighestAtOrBelowByPrefix ¶
func FindHighestAtOrBelowByPrefix(r storage.Reader, prefix []byte, height uint64, entity interface{}) (errToReturn error)
FindHighestAtOrBelowByPrefix is for database entries that are indexed by block height. It is suitable to search keys with the format prefix` + `height` (where "+" denotes concatenation of binary strings). The height is encoded as Big-Endian (entries with numerically smaller height have lexicographically smaller key). The function finds the *highest* key with the given prefix and height equal to or below the given height.
func IterateKeys ¶
func IterateKeys(r storage.Reader, startPrefix []byte, endPrefix []byte, iterFunc IterationFunc, opt storage.IteratorOption) (errToReturn error)
IterateKeys will iterate over all entries in the database, where the key starts with a prefixes in the range [startPrefix, endPrefix] (both inclusive). No errors expected during normal operations.
func IterateKeysByPrefixRange ¶
func IterateKeysByPrefixRange(r storage.Reader, startPrefix []byte, endPrefix []byte, check func(key []byte) error) error
IterateKeysByPrefixRange will iterate over all entries in the database, where the key starts with a prefixes in the range [startPrefix, endPrefix] (both inclusive). We require that startPrefix <= endPrefix (otherwise this function errors). On every such key, the `check` function is called. If `check` errors, iteration is aborted. In other words, error returned by the iteration functions will be propagated to the caller. No errors expected during normal operations.
func KeyExists ¶
KeyExists returns true if a key exists in the database. When this returned function is executed (and only then), it will write into the `keyExists` whether the key exists. No errors are expected during normal operation.
func KeyPartToBytes ¶
func KeyPartToBytes(v interface{}) []byte
func MakePrefix ¶
func RemoveByKey ¶
RemoveByKey removes the entity with the given key, if it exists. If it doesn't exist, this is a no-op. Error returns: * generic error in case of unexpected database error
func RemoveByKeyPrefix ¶
RemoveByKeyPrefix removes all keys with the given prefix Error returns: * generic error in case of unexpected database error
func RemoveByKeyRange ¶
func RemoveByKeyRange(reader storage.Reader, w storage.Writer, startPrefix []byte, endPrefix []byte) error
RemoveByKeyRange removes all keys with a prefix that falls within the range [start, end], both inclusive. It returns error if endPrefix < startPrefix no other errors are expected during normal operation
func RemoveByPrefix ¶
func RemoveByRange ¶
func RetrieveByKey ¶
RetrieveByKey will retrieve the binary data under the given key from the database and decode it into the given entity. The provided entity needs to be a pointer to an initialized entity of the correct type. Error returns:
- storage.ErrNotFound if the key does not exist in the database
- generic error in case of unexpected failure from the database layer, or failure to decode an existing database value
func Traverse ¶
func Traverse(prefix []byte, iterFunc IterationFunc, opt storage.IteratorOption) func(storage.Reader) error
func TraverseByPrefix ¶
func TraverseByPrefix(r storage.Reader, prefix []byte, iterFunc IterationFunc, opt storage.IteratorOption) error
Traverse will iterate over all keys with the given prefix error returned by the iteration functions will be propagated to the caller. No other errors are expected during normal operation.
func UpsertByKey ¶
UpsertByKey will encode the given entity using msgpack and will insert the resulting binary data under the provided key. If the key already exists, the value will be overwritten. Error returns:
- generic error in case of unexpected failure from the database layer or encoding failure.
Types ¶
type Callbacks ¶
type Callbacks struct { sync.RWMutex // protect callbacks // contains filtered or unexported fields }
func (*Callbacks) AddCallback ¶
func (*Callbacks) NotifyCallbacks ¶
type CheckFunc ¶
CheckFunc is a function that checks if the value should be read and decoded. return (true, nil) to read the value and pass it to the CreateFunc and HandleFunc for decoding return (false, nil) to skip reading the value return (false, err) if running into any error, the iteration should be stopped. when making a CheckFunc to be used in the IterationFunc to iterate over the keys, a sentinel error can be defined and checked to stop the iteration early, such as finding the first key that match certain condition.
type CreateFunc ¶
type CreateFunc func() interface{}
CreateFunc returns a pointer to an initialized entity that we can potentially decode the next value into during a badger DB iteration.
type HandleFunc ¶
type HandleFunc func() error
HandleFunc is a function that starts the processing of the current key-value pair during a badger iteration. It should be called after the key was checked and the entity was decoded. No errors are expected during normal operation. Any errors will halt the iteration.
type IterationFunc ¶
type IterationFunc func() (CheckFunc, CreateFunc, HandleFunc)