storage

package
v0.0.0-...-8aa4d74 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 License: GPL-3.0 Imports: 15 Imported by: 1

Documentation

Overview

Provides a replacement for LevelDBBackend suitable for unit tests

LevelDB allows one to create a memory DB where we can store test data during our unit tests

Index

Constants

This section is empty.

Variables

View Source
var DefaultMaxLimitListOptions uint64 = 100
View Source
var SupportedStorageType []string = []string{
	"memory",
	"file",
}

Functions

This section is empty.

Types

type BatchCore

type BatchCore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBatchCore

func NewBatchCore(core LevelDBCore) *BatchCore

func (*BatchCore) Commit

func (bb *BatchCore) Commit() (err error)

func (*BatchCore) Delete

func (bb *BatchCore) Delete(key []byte, opt *leveldbOpt.WriteOptions) error

func (*BatchCore) Discard

func (bb *BatchCore) Discard()

func (*BatchCore) Dump

func (bb *BatchCore) Dump() []byte

func (*BatchCore) Get

func (bb *BatchCore) Get(key []byte, opt *leveldbOpt.ReadOptions) (b []byte, err error)

func (*BatchCore) Has

func (bb *BatchCore) Has(key []byte, opt *leveldbOpt.ReadOptions) (bool, error)

func (*BatchCore) NewIterator

NewIterator does not work with `BatchBackend`

func (*BatchCore) Put

func (bb *BatchCore) Put(key []byte, v []byte, opt *leveldbOpt.WriteOptions) error

func (*BatchCore) Write

func (bb *BatchCore) Write(batch *leveldb.Batch, opt *leveldbOpt.WriteOptions) (err error)

Write will write the existing contents of `BatchBackend.batch` and then argument, batch will be written.

type Committable

type Committable interface {
	Discard()
	Commit() error
}

type Config

type Config url.URL

func NewConfigFromString

func NewConfigFromString(s string) (e *Config, err error)

func NewConfigFromURL

func NewConfigFromURL(u *url.URL) *Config

func ParseConfig

func ParseConfig(s string) (u *Config, err error)

func (*Config) Query

func (e *Config) Query() url.Values

func (*Config) String

func (e *Config) String() string

func (*Config) UnmarshalJSON

func (e *Config) UnmarshalJSON(b []byte) error

type DefaultListOptions

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

func NewDefaultListOptions

func NewDefaultListOptions(reverse bool, cursor []byte, limit uint64) *DefaultListOptions

func (DefaultListOptions) Cursor

func (o DefaultListOptions) Cursor() []byte

func (DefaultListOptions) Encode

func (o DefaultListOptions) Encode() string

func (DefaultListOptions) Limit

func (o DefaultListOptions) Limit() uint64

func (DefaultListOptions) Reverse

func (o DefaultListOptions) Reverse() bool

func (*DefaultListOptions) SetCursor

func (o *DefaultListOptions) SetCursor(c []byte) ListOptions

func (*DefaultListOptions) SetLimit

func (o *DefaultListOptions) SetLimit(l uint64) ListOptions

func (*DefaultListOptions) SetReverse

func (o *DefaultListOptions) SetReverse(r bool) ListOptions

func (DefaultListOptions) Template

func (o DefaultListOptions) Template() string

func (DefaultListOptions) URLValues

func (o DefaultListOptions) URLValues() url.Values

type Item

type Item struct {
	Key   string
	Value interface{}
}

type IterItem

type IterItem struct {
	N     uint64
	Key   []byte
	Value []byte
}

func (IterItem) Clone

func (i IterItem) Clone() IterItem

type LevelDBBackend

type LevelDBBackend struct {
	DB *leveldb.DB

	Core LevelDBCore
}

func NewStorage

func NewStorage(config *Config) (st *LevelDBBackend, err error)

func NewTestStorage

func NewTestStorage() *LevelDBBackend

Returns:

A new memory DB

func (*LevelDBBackend) Close

func (st *LevelDBBackend) Close() error

func (*LevelDBBackend) Commit

func (st *LevelDBBackend) Commit() error

func (*LevelDBBackend) Discard

func (st *LevelDBBackend) Discard() error

func (*LevelDBBackend) Get

func (st *LevelDBBackend) Get(k string, i interface{}) (err error)

func (*LevelDBBackend) GetIterator

func (st *LevelDBBackend) GetIterator(prefix string, option ListOptions) (func() (IterItem, bool), func())

func (*LevelDBBackend) GetRaw

func (st *LevelDBBackend) GetRaw(k string) (b []byte, err error)

func (*LevelDBBackend) Has

func (st *LevelDBBackend) Has(k string) (bool, error)

func (*LevelDBBackend) Init

func (st *LevelDBBackend) Init(config *Config) (err error)

func (*LevelDBBackend) New

func (st *LevelDBBackend) New(k string, v interface{}) error

func (*LevelDBBackend) News

func (st *LevelDBBackend) News(vs ...Item) (err error)

func (*LevelDBBackend) OpenBatch

func (st *LevelDBBackend) OpenBatch() (*LevelDBBackend, error)

func (*LevelDBBackend) OpenSnapshot

func (st *LevelDBBackend) OpenSnapshot() (*LevelDBBackend, error)

func (*LevelDBBackend) OpenTransaction

func (st *LevelDBBackend) OpenTransaction() (*LevelDBBackend, error)

func (*LevelDBBackend) Release

func (st *LevelDBBackend) Release() error

func (*LevelDBBackend) Remove

func (st *LevelDBBackend) Remove(k string) error

func (*LevelDBBackend) Set

func (st *LevelDBBackend) Set(k string, v interface{}) (err error)

func (*LevelDBBackend) Sets

func (st *LevelDBBackend) Sets(vs ...Item) (err error)

func (*LevelDBBackend) Walk

func (st *LevelDBBackend) Walk(prefix string, option *WalkOption, walkFunc WalkFunc) error

type ListOptions

type ListOptions interface {
	Reverse() bool
	SetReverse(bool) ListOptions
	Cursor() []byte
	SetCursor([]byte) ListOptions
	Limit() uint64
	SetLimit(uint64) ListOptions
	Template() string
	URLValues() url.Values
	Encode() string
}

type Model

type Model struct {
}

type Snapshot

type Snapshot struct {
	*leveldb.Snapshot
}

func NewSnapshot

func NewSnapshot(st *LevelDBBackend) (*Snapshot, error)

func (*Snapshot) Delete

func (s *Snapshot) Delete([]byte, *leveldbOpt.WriteOptions) error

func (*Snapshot) Put

func (s *Snapshot) Put([]byte, []byte, *leveldbOpt.WriteOptions) error

func (*Snapshot) Write

type StateDB

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

func NewStateDB

func NewStateDB(st *LevelDBBackend) *StateDB

func (*StateDB) Commit

func (s *StateDB) Commit() error

func (*StateDB) Discard

func (s *StateDB) Discard() error

func (*StateDB) Get

func (s *StateDB) Get(k string, i interface{}) error

func (*StateDB) GetIterator

func (s *StateDB) GetIterator(prefix string, reverse bool) (func() (IterItem, bool), func())

func (*StateDB) Has

func (s *StateDB) Has(k string) (bool, error)

func (*StateDB) MakeHash

func (s *StateDB) MakeHash() ([]byte, error)

func (*StateDB) MakeHashString

func (s *StateDB) MakeHashString() (string, error)

func (*StateDB) New

func (s *StateDB) New(k string, i interface{}) error

func (*StateDB) News

func (s *StateDB) News(vs ...Item) error

func (*StateDB) Remove

func (s *StateDB) Remove(k string) error

func (*StateDB) Set

func (s *StateDB) Set(k string, i interface{}) error

func (*StateDB) Sets

func (s *StateDB) Sets(vs ...Item) error

type WalkFunc

type WalkFunc func(key, value []byte) (bool, error)

type WalkOption

type WalkOption struct {
	Cursor  string
	Limit   uint64
	Reverse bool
}

func NewWalkOption

func NewWalkOption(cursor string, limit uint64, reverse bool) *WalkOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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