storage

package
v0.0.0-...-be1c10e Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StorageV1
	//		- initial
	StorageV1 int32 = 1 + iota
	// StorageV2
	//		- record bitlength associated with poc pk
	StorageV2
	// StorageV3
	//		- since 1.1.0
	//		- save blocks to disk
	StorageV3

	CurrentStorageVersion int32 = StorageV3
)
View Source
const (
	KiB = 1024
	MiB = KiB * 1024
	GiB = MiB * 1024
)

Variables

View Source
var (
	ErrDbUnknownType       = errors.New("non-existent database type")
	ErrInvalidKey          = errors.New("invalid key")
	ErrInvalidValue        = errors.New("invalid value")
	ErrInvalidBatch        = errors.New("invalid batch")
	ErrInvalidArgument     = errors.New("invalid argument")
	ErrNotFound            = errors.New("not found")
	ErrIncompatibleStorage = errors.New("incompatible storage")
)

Functions

func CheckCompatibility

func CheckCompatibility(dbtype, storPath string) error

func ReadVersion

func ReadVersion(path string) (string, int32, error)

func RegisterDriver

func RegisterDriver(instance StorageDriver)

func RegisteredDbTypes

func RegisteredDbTypes() []string

func WriteVersion

func WriteVersion(path, dbtype string, version int32) error

Types

type Batch

type Batch interface {
	Release()
	Put(key, value []byte) error
	Delete(key []byte) error
	Reset()
}

type Iterator

type Iterator interface {
	Release()
	Error() error
	Seek(key []byte) bool
	Next() bool
	Key() []byte
	Value() []byte
}

type Range

type Range struct {
	// Start of the key range, include in the range.
	Start []byte

	// Limit of the key range, not include in the range.
	Limit []byte
}

Range is a key range.

func BytesPrefix

func BytesPrefix(prefix []byte) *Range

func (*Range) IsPrefix

func (r *Range) IsPrefix() bool

type Storage

type Storage interface {
	Close() error
	// Get returns ErrNotFound if key not exist
	Get(key []byte) ([]byte, error)
	Put(key, value []byte) error
	Has(key []byte) (bool, error)
	Delete(key []byte) error
	Write(batch Batch) error
	NewBatch() Batch
	NewIterator(slice *Range) Iterator
}

func CreateStorage

func CreateStorage(dbtype, dbpath string, args ...interface{}) (s Storage, err error)

CreateStorage intializes and opens a database.

func OpenStorage

func OpenStorage(dbtype, dbpath string, readonly bool, args ...interface{}) (s Storage, err error)

CreateStorage opens an existing database.

type StorageDriver

type StorageDriver struct {
	DbType        string
	CreateStorage func(storPath string, args ...interface{}) (s Storage, err error)
	OpenStorage   func(storPath string, readonly bool, args ...interface{}) (s Storage, err error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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