chaindb

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: LGPL-3.0 Imports: 6 Imported by: 13

README

chaindb

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(file string) (*BadgerDB, error)

NewBadgerDB initializes badgerDB instance

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) 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() Iterable

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

type Batch

type Batch interface {
	PutItem
	ValueSize() int
	Write() error
	Reset()
	Delete(key []byte) error
}

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
}

Config defines configurations for BadgerService instance

type Database

type Database interface {
	PutItem
	Iteratee
	Get(key []byte) ([]byte, error)
	Has(key []byte) (bool, error)
	Del(key []byte) error
	NewBatch() Batch
	Close() error
	Path() string
}

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 Iterable

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

Iterable struct contains a transaction, iterator and context fields released, initialized

func (*Iterable) Key

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

Key returns an item key

func (*Iterable) Next

func (i *Iterable) 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 (*Iterable) Release

func (i *Iterable) Release()

Release closes the iterator, discards the created transaction and sets released value to true

func (*Iterable) Released

func (i *Iterable) Released() bool

Released returns the boolean indicating whether the iterator and transaction was successfully released

func (*Iterable) Seek

func (i *Iterable) 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 (*Iterable) Value

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

Value returns a copy of the value of the item

type Iteratee

type Iteratee interface {
	NewIterator() Iterable
}

Iteratee wraps the NewIterator methods of BadgerService

type Iterator

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

Iterator iterates over BadgerDBs key/value pairs in ascending key order must be released after use

type MemDatabase

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

MemDatabase test memory database, data is not persisted

func NewMemDatabase

func NewMemDatabase() *MemDatabase

NewMemDatabase returns an initialized mapping used for test database

func (*MemDatabase) Close

func (db *MemDatabase) Close() error

Close ...

func (*MemDatabase) Del

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

Del removes the key from the mapping

func (*MemDatabase) Get

func (db *MemDatabase) Get(k []byte) ([]byte, error)

Get returns the given key []byte

func (*MemDatabase) Has

func (db *MemDatabase) Has(k []byte) (bool, error)

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

func (*MemDatabase) Keys

func (db *MemDatabase) Keys() [][]byte

Keys returns [][]byte of mapping keys

func (*MemDatabase) NewBatch

func (db *MemDatabase) NewBatch() Batch

NewBatch ...

func (*MemDatabase) NewIterator

func (db *MemDatabase) NewIterator() Iterable

NewIterator ...

func (*MemDatabase) Path

func (db *MemDatabase) Path() string

Path ...

func (*MemDatabase) Put

func (db *MemDatabase) Put(k []byte, v []byte) error

Put puts the given key / value into the mapping

type PutItem

type PutItem interface {
	Put(key []byte, value []byte) error
}

PutItem wraps the database write operation supported by regular database.

type Reader

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

Reader interface

type Writer

type Writer interface {
	PutItem
	Del(key []byte) error
}

Writer interface

Jump to

Keyboard shortcuts

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