store

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgerDB

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

BadgerDB is a wrapper around a BadgerDB backend database that implements the DB interface.

func (*BadgerDB) All

func (bdb *BadgerDB) All(prefix []byte) ([][]byte, error)

All returns all values for the given namespace and prefix.

func (*BadgerDB) Close

func (bdb *BadgerDB) Close() error

Close implements the DB interface. It closes the connection to the underlying BadgerDB database as well as invoking the context's cancel function.

func (*BadgerDB) Count

func (bdb *BadgerDB) Count(prefix []byte) (int, error)

Count returns the number of entries that match namespace and prefix

func (*BadgerDB) Each

func (bdb *BadgerDB) Each(prefix []byte, callback KVStoreEachFunc) error

Each iterates over all items that match namespace and prefix

func (*BadgerDB) ErrNotFound

func (bdb *BadgerDB) ErrNotFound() error

ErrNotFound is the error badger returns when it can't find a key in the database

func (*BadgerDB) Get

func (bdb *BadgerDB) Get(key []byte) ([]byte, error)

Get implements the DB interface. It attempts to get a value for a given key and namespace. If the key does not exist in the provided namespace, an error is returned, otherwise the retrieved value.

func (*BadgerDB) Has

func (bdb *BadgerDB) Has(key []byte) (ok bool, err error)

Has implements the DB interface. It returns a boolean reflecting if the datbase has a given key for a namespace or not. An error is only returned if an error to Get would be returned that is not of type badger.ErrKeyNotFound.

func (*BadgerDB) Remove

func (bdb *BadgerDB) Remove(prefix []byte) error

Remove removes a single entry from the database

func (*BadgerDB) Set

func (bdb *BadgerDB) Set(key, value []byte) error

Set implements the DB interface. It attempts to store a value for a given key and namespace. If the key/value pair cannot be saved, an error is returned.

func (*BadgerDB) SetEx

func (bdb *BadgerDB) SetEx(key, value []byte, ttl time.Duration) error

SetEx stores the given key and value for the time given by ttl If the key/value pair can't be saved an error is returned

type KVStore

type KVStore interface {
	Get(key []byte) (value []byte, err error)
	SetEx(key, value []byte, ttl time.Duration) error
	Set(key, value []byte) error
	Has(key []byte) (bool, error)
	All(prefix []byte) ([][]byte, error)
	Count(prefix []byte) (int, error)
	Remove(prefix []byte) error
	Each(prefix []byte, callback KVStoreEachFunc) error
	ErrNotFound() error
	Close() error
}

KVStore defines an embedded key/value store database interface.

func NewBadgerDB

func NewBadgerDB(ctx context.Context, dataDir string) (KVStore, error)

NewBadgerDB returns a new initialized BadgerDB database implementing the DB interface. If the database cannot be initialized, an error will be returned.

type KVStoreEachFunc

type KVStoreEachFunc func([]byte)

KVStoreEachFunc is the function that gets called on each item in the Each function

Jump to

Keyboard shortcuts

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