db

package
v0.0.0-...-c56c372 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: Unlicense Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BadgerAlertNamespace defines the alerts BadgerDB namespace.
	BadgerAlertNamespace = []byte("alerts")
)

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) 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) Get

func (bdb *BadgerDB) Get(namespace, key []byte) (value []byte, err 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(namespace, 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) Set

func (bdb *BadgerDB) Set(namespace, 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.

type DB

type DB interface {
	Get(namespace, key []byte) (value []byte, err error)
	Set(namespace, key, value []byte) error
	Has(namespace, key []byte) (bool, error)
	Close() error
}

DB defines an embedded key/value store database interface.

func NewBadgerDB

func NewBadgerDB(dataDir string) (DB, error)

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

Jump to

Keyboard shortcuts

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