database

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BadgerAlertNamespace = []byte("alerts")

BadgerAlertNamespace defines the alerts BadgerDB namespace.

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 string, 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) Insert

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

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

func (*BadgerDB) Update

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

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

type DBInstance

type DBInstance interface {
	Get(namespace, key []byte) (value string, err error)
	Update(namespace, key, value []byte) error
	Insert(namespace, key, value []byte) error
	Has(namespace, key []byte) (bool, error)
	Close() error
}

DBInstance defines an embedded key/value store database interface.

var (
	DB               DBInstance
	RequestNamespace = []byte("requestNamespace")
)

func NewBadgerDB

func NewBadgerDB(dataDir string) (DBInstance, 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