db

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2018 License: Apache-2.0 Imports: 5 Imported by: 16

Documentation

Index

Constants

View Source
const (
	// Put indicate the type of write operation to be Put
	Put int32 = iota
	// Delete indicate the type of write operation to be Delete
	Delete int32 = 1
	// PutIfNotExists indicate the type of write operation to be PutIfNotExists
	PutIfNotExists int32 = 2
)

Variables

View Source
var (
	// ErrInvalidDB indicates invalid operation attempted to Blockchain database
	ErrInvalidDB = errors.New("invalid DB operation")
	// ErrNotExist indicates certain item does not exist in Blockchain database
	ErrNotExist = errors.New("not exist in DB")
	// ErrAlreadyExist indicates certain item already exists in Blockchain database
	ErrAlreadyExist = errors.New("already exist in DB")
)

Functions

This section is empty.

Types

type KVStore

type KVStore interface {
	lifecycle.StartStopper

	// Put insert or update a record identified by (namespace, key)
	Put(string, []byte, []byte) error
	// Put puts a record only if (namespace, key) doesn't exist, otherwise return ErrAlreadyExist
	PutIfNotExists(string, []byte, []byte) error
	// Get gets a record by (namespace, key)
	Get(string, []byte) ([]byte, error)
	// Delete deletes a record by (namespace, key)
	Delete(string, []byte) error
	// Batch return a kv store batch api object
	Batch() KVStoreBatch
}

KVStore is the interface of KV store.

func NewBoltDB

func NewBoltDB(path string, options *bolt.Options) KVStore

NewBoltDB instantiates a boltdb based KV store

func NewMemKVStore

func NewMemKVStore() KVStore

NewMemKVStore instantiates an in-memory KV store

type KVStoreBatch added in v0.3.0

type KVStoreBatch interface {
	// Put insert or update a record identified by (namespace, key)
	Put(string, []byte, []byte, string, ...interface{}) error
	// PutIfNotExists puts a record only if (namespace, key) doesn't exist, otherwise return ErrAlreadyExist
	PutIfNotExists(string, []byte, []byte, string, ...interface{}) error
	// Delete deletes a record by (namespace, key)
	Delete(string, []byte, string, ...interface{}) error
	// Clear clear batch write queue
	Clear() error
	// Commit commit queued write to db
	Commit() error
}

KVStoreBatch is the interface of KV store.

func NewBaseKVStoreBatch added in v0.3.0

func NewBaseKVStoreBatch() KVStoreBatch

NewBaseKVStoreBatch instantiates an in-memory KV store

func NewBoltDBBatch added in v0.3.0

func NewBoltDBBatch(bdb *boltDB) KVStoreBatch

NewBoltDBBatch instantiates a boltdb based KV store

func NewMemKVStoreBatch added in v0.3.0

func NewMemKVStoreBatch(data *sync.Map, bucket *map[string]struct{}) KVStoreBatch

NewMemKVStoreBatch instantiates an in-memory KV store

Jump to

Keyboard shortcuts

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