db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2020 License: CC0-1.0 Imports: 2 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 defines a wrapper type around a Badger DB that implements the DB interface. It mainly provides transaction abstractions.

func (*BadgerDB) Close

func (bdb *BadgerDB) Close() error

Close closes the Badger DB instance and returns an error upon failure.

func (*BadgerDB) Delete

func (bdb *BadgerDB) Delete(key []byte) error

Delete attempts to remove a value by key from Badger DB returning an error upon failure.

func (*BadgerDB) Get

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

Get returns a value for a given key. It returns badger.ErrKeyNotFound if the value is not found.

func (*BadgerDB) Has

func (bdb *BadgerDB) Has(key []byte) bool

Has returns a boolean determining if the underlying Badger DB has a given key or not.

func (*BadgerDB) IteratePrefix

func (bdb *BadgerDB) IteratePrefix(prefix []byte, cb func(k, v []byte) bool)

IteratePrefix iterates over a series of key/value pairs where each key contains the provided prefix. For each key/value pair, a cb function is invoked. If cb returns true, iteration is halted.

func (*BadgerDB) Set

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

Set attempts to set a key/value pair into Badger DB returning an error upon failure.

type DB

type DB interface {
	Get(key []byte) ([]byte, error)
	Has(key []byte) bool
	Set(key, value []byte) error
	Delete(key []byte) error
	IteratePrefix(prefix []byte, cb func(k, v []byte) bool)
	Close() error
}

DB defines the persistence interface for tmcrawl.

func NewBadgerDB

func NewBadgerDB(dataDir, dbName string) (DB, error)

NewBadgerDB returns a wrapper around a Badger DB that implements the DB interface. It will create all the necessary Badger DB buckets if they don't already exist.

func NewBadgerMemDB

func NewBadgerMemDB() (DB, error)

NewBadgerMemDB return a pure in-memory Badger DB instance that implements the DB interface. Data is stored only in-memory and should be used for testing purposes only.

Jump to

Keyboard shortcuts

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