chaindb

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: LGPL-3.0 Imports: 10 Imported by: 13

README

chaindb

Discord

go key-value store using badgerDB

usage

go get github.com/ChainSafe/chaindb

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = badger.ErrKeyNotFound

ErrKeyNotFound is returned if there is a database get for a key that does not exist

Functions

This section is empty.

Types

type BadgerDB

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

BadgerDB contains directory path to data and db instance

func NewBadgerDB

func NewBadgerDB(cfg *Config) (*BadgerDB, error)

NewBadgerDB initializes badgerDB instance

func (*BadgerDB) ClearAll added in v0.1.5

func (db *BadgerDB) ClearAll() error

ClearAll would delete all the data stored in DB.

func (*BadgerDB) Close

func (db *BadgerDB) Close() error

Close closes a DB

func (*BadgerDB) Del

func (db *BadgerDB) Del(key []byte) error

Del removes the key from the queue and database

func (*BadgerDB) Flush added in v0.1.0

func (db *BadgerDB) Flush() error

Flush commits pending writes to disk

func (*BadgerDB) Get

func (db *BadgerDB) Get(key []byte) (data []byte, err error)

Get returns the given key

func (*BadgerDB) Has

func (db *BadgerDB) Has(key []byte) (exists bool, err error)

Has checks the given key exists already; returning true or false

func (*BadgerDB) NewBatch

func (db *BadgerDB) NewBatch() Batch

NewBatch returns batchWriter with a badgerDB instance and an initialized mapping

func (*BadgerDB) NewIterator

func (db *BadgerDB) NewIterator() Iterator

NewIterator returns a new iterator within the Iterator struct along with a new transaction

func (*BadgerDB) Path

func (db *BadgerDB) Path() string

Path returns the path to the database directory.

func (*BadgerDB) Put

func (db *BadgerDB) Put(key []byte, value []byte) error

Put puts the given key / value to the queue

func (*BadgerDB) Subscribe added in v0.1.5

func (db *BadgerDB) Subscribe(ctx context.Context, cb func(kv *KVList) error, prefixes []pb.Match) error

Subscribe to watch for changes for the given prefixes

type BadgerIterator added in v0.1.0

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

BadgerIterator struct contains a transaction, iterator and init.

func (*BadgerIterator) Key added in v0.1.0

func (i *BadgerIterator) Key() []byte

Key returns an item key

func (*BadgerIterator) Next added in v0.1.0

func (i *BadgerIterator) Next() bool

Next rewinds the iterator to the zero-th position if uninitialized, and then will advance the iterator by one returns bool to ensure access to the item

func (*BadgerIterator) Release added in v0.1.0

func (i *BadgerIterator) Release()

Release closes the iterator and discards the created transaction.

func (*BadgerIterator) Seek added in v0.1.0

func (i *BadgerIterator) Seek(key []byte)

Seek will look for the provided key if present and go to that position. If absent, it would seek to the next smallest key

func (*BadgerIterator) Valid added in v0.1.5

func (i *BadgerIterator) Valid() bool

Valid returns whether the current iterator position has an item.

func (*BadgerIterator) Value added in v0.1.0

func (i *BadgerIterator) Value() []byte

Value returns a copy of the value of the item

type Batch

type Batch interface {
	Writer

	ValueSize() int
	Reset()
}

Batch is a write-only operation.

func NewTableBatch

func NewTableBatch(db Database, prefix string) Batch

NewTableBatch returns a Batch object which prefixes all keys with a given string.

type Config

type Config struct {
	DataDir  string
	InMemory bool
	Compress bool
}

Config defines configurations for BadgerDB instance

type Database

type Database interface {
	Reader
	Writer
	io.Closer

	NewBatch() Batch
	Path() string
	NewIterator() Iterator
	Subscribe(ctx context.Context, cb func(kv *KVList) error, prefixes []pb.Match) error
	ClearAll() error
}

Database wraps all database operations. All methods are safe for concurrent use.

func NewTable

func NewTable(db Database, prefix string) Database

NewTable returns a Database object that prefixes all keys with a given string.

type Iterator

type Iterator interface {
	Valid() bool
	Next() bool
	Key() []byte
	Value() []byte
	Release()
}

Iterator iterates over key/value pairs in ascending key order. Must be released after use.

type KVList added in v0.1.5

type KVList = badger.KVList

type Reader

type Reader interface {
	Get(key []byte) ([]byte, error)
	Has(key []byte) (bool, error)
}

Reader interface

type Writer

type Writer interface {
	Put(key []byte, value []byte) error
	Del(key []byte) error
	Flush() error
}

Writer interface

Jump to

Keyboard shortcuts

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