kvdb

package
v0.0.0-...-168a2c3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const IdealBatchSize = 100 * 1024

IdealBatchSize was determined empirically. Code using batches should try to add this much data to the batch.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgerDatabase

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

BadgerDatabase is a kvbd.Database wrapper of *badger.DB

func NewBadgerDatabase

func NewBadgerDatabase(db *badger.DB) *BadgerDatabase

NewBadgerDatabase wraps *badger.DB

func (*BadgerDatabase) Close

func (w *BadgerDatabase) Close()

Close leaves underlying database.

func (*BadgerDatabase) Delete

func (w *BadgerDatabase) Delete(key []byte) error

Delete removes key-value pair by key.

func (*BadgerDatabase) Get

func (w *BadgerDatabase) Get(key []byte) (res []byte, err error)

Get returns key-value pair by key.

func (*BadgerDatabase) Has

func (w *BadgerDatabase) Has(key []byte) (bool, error)

Has checks if key is in the db.

func (*BadgerDatabase) NewBatch

func (w *BadgerDatabase) NewBatch() Batch

NewBatch creates new batch.

func (*BadgerDatabase) Put

func (w *BadgerDatabase) Put(key []byte, value []byte) error

Put puts key-value pair into db.

type Batch

type Batch interface {
	Putter
	Deleter
	ValueSize() int // amount of data in the batch
	Write() error
	// Reset resets the batch for reuse
	Reset()
}

Batch is a write-only database that commits changes to its host database when Write is called. Batch cannot be used concurrently.

func NewTableBatch

func NewTableBatch(db Database, prefix string) Batch

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

type Database

type Database interface {
	Putter
	Deleter
	Get(key []byte) ([]byte, error)
	Has(key []byte) (bool, error)
	Close()
	NewBatch() Batch
}

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 Deleter

type Deleter interface {
	Delete(key []byte) error
}

Deleter wraps the database delete operation supported by both batches and regular databases.

type MemDatabase

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

MemDatabase is a kvbd.Database wrapper of map[string][]byte Do not use for any production it does not get persisted

func NewMemDatabase

func NewMemDatabase() *MemDatabase

NewMemDatabase wraps map[string][]byte

func (*MemDatabase) Close

func (w *MemDatabase) Close()

Close leaves underlying database.

func (*MemDatabase) Delete

func (w *MemDatabase) Delete(key []byte) error

Delete removes key-value pair by key.

func (*MemDatabase) Get

func (w *MemDatabase) Get(key []byte) ([]byte, error)

Get returns key-value pair by key.

func (*MemDatabase) Has

func (w *MemDatabase) Has(key []byte) (bool, error)

Has checks if key is in the db.

func (*MemDatabase) Keys

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

Keys returns slice of keys in the db.

func (*MemDatabase) Len

func (w *MemDatabase) Len() int

Len returns count of key-values pairs in the db.

func (*MemDatabase) NewBatch

func (w *MemDatabase) NewBatch() Batch

NewBatch creates new batch.

func (*MemDatabase) Put

func (w *MemDatabase) Put(key []byte, value []byte) error

Put puts key-value pair into db.

type Putter

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

Putter wraps the database write operation supported by both batches and regular databases.

Jump to

Keyboard shortcuts

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