db

package
Version: v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: GPL-3.0 Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("key not found")

Functions

func IPFSexport

func IPFSexport() error

func LoadJSON

func LoadJSON(storage Storage, key []byte, v interface{}) error

func StoreJSON

func StoreJSON(tx Tx, key []byte, v interface{}) error

Types

type KV

type KV struct {
	K []byte
	V []byte
}

type LevelDbStorage

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

func NewLevelDbStorage

func NewLevelDbStorage(path string, errorIfMissing bool) (*LevelDbStorage, error)

func (*LevelDbStorage) Close

func (l *LevelDbStorage) Close()

func (*LevelDbStorage) Get

func (l *LevelDbStorage) Get(key []byte) ([]byte, error)

Get retreives a value from a key in the mt.Lvl

func (*LevelDbStorage) Info

func (l *LevelDbStorage) Info() string

func (*LevelDbStorage) Iterate

func (l *LevelDbStorage) Iterate(f func([]byte, []byte) (bool, error)) error

func (*LevelDbStorage) LevelDB

func (l *LevelDbStorage) LevelDB() *leveldb.DB

func (*LevelDbStorage) List

func (l *LevelDbStorage) List(limit int) ([]KV, error)

func (*LevelDbStorage) NewTx

func (l *LevelDbStorage) NewTx() (Tx, error)

func (*LevelDbStorage) RawDump

func (l *LevelDbStorage) RawDump() error

func (*LevelDbStorage) WithPrefix

func (l *LevelDbStorage) WithPrefix(prefix []byte) Storage

type LevelDbStorageTx

type LevelDbStorageTx struct {
	*LevelDbStorage
	// contains filtered or unexported fields
}

func (*LevelDbStorageTx) Add

func (tx *LevelDbStorageTx) Add(atx Tx)

func (*LevelDbStorageTx) Close

func (l *LevelDbStorageTx) Close()

func (*LevelDbStorageTx) Commit

func (l *LevelDbStorageTx) Commit() error

func (*LevelDbStorageTx) Get

func (l *LevelDbStorageTx) Get(key []byte) ([]byte, error)

Get retreives a value from a key in the mt.Lvl

func (*LevelDbStorageTx) Put

func (tx *LevelDbStorageTx) Put(k, v []byte)

Insert saves a key:value into the mt.Lvl

type MemoryStorage

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

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

func (*MemoryStorage) Close

func (m *MemoryStorage) Close()

func (*MemoryStorage) Get

func (l *MemoryStorage) Get(key []byte) ([]byte, error)

Get retreives a value from a key in the mt.Lvl

func (*MemoryStorage) Info

func (l *MemoryStorage) Info() string

func (*MemoryStorage) Iterate

func (l *MemoryStorage) Iterate(f func([]byte, []byte) (bool, error)) error

func (*MemoryStorage) List

func (l *MemoryStorage) List(limit int) ([]KV, error)

func (*MemoryStorage) NewTx

func (m *MemoryStorage) NewTx() (Tx, error)

func (*MemoryStorage) WithPrefix

func (m *MemoryStorage) WithPrefix(prefix []byte) Storage

type MemoryStorageTx

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

func (*MemoryStorageTx) Add

func (tx *MemoryStorageTx) Add(atx Tx)

func (*MemoryStorageTx) Close

func (tx *MemoryStorageTx) Close()

func (*MemoryStorageTx) Commit

func (tx *MemoryStorageTx) Commit() error

func (*MemoryStorageTx) Get

func (tx *MemoryStorageTx) Get(key []byte) ([]byte, error)

func (*MemoryStorageTx) Put

func (tx *MemoryStorageTx) Put(k, v []byte)

type Storage

type Storage interface {
	NewTx() (Tx, error)
	WithPrefix(prefix []byte) Storage
	Get([]byte) ([]byte, error)
	List(int) ([]KV, error)
	Close()
	Info() string
	Iterate(func([]byte, []byte) (bool, error)) error
}

type StorageList

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

StorageList allows storing a list of key values that are also stored by index number.

func NewStorageList

func NewStorageList(dbPrefix []byte) *StorageList

NewStorageList creates a new StorageList that will store the contents under the dbPrefix in a Storage.

func (*StorageList) Append

func (sl *StorageList) Append(tx Tx, key []byte, value interface{}) error

Append adds a new key value entry to the StorageList in an open db transaction.

func (*StorageList) Get

func (sl *StorageList) Get(tx Tx, key []byte, value interface{}) error

GetByIdx returns the value given the key of the StorageList in an open db transaction.

func (*StorageList) GetByIdx

func (sl *StorageList) GetByIdx(tx Tx, idx uint32, value interface{}) ([]byte, error)

GetByIdx returns the key value given the index of the StorageList in an open db transaction.

func (*StorageList) Init

func (sl *StorageList) Init(tx Tx)

Init initializes the Storage list in an open db transaction.

func (*StorageList) Length

func (sl *StorageList) Length(tx Tx) (uint32, error)

Length returns the number of elements in the StorageList in an open db transaction.

type StorageValue

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

StorageValue allows storing a uint32 persistently

func NewStorageValue

func NewStorageValue(dbKey []byte) *StorageValue

NewStorageValue creates a new StorageValue that uses the dbKey in a Storage to store the value.

func (*StorageValue) Get

func (sv *StorageValue) Get(tx Tx) (uint32, error)

Get returns the current value in an open db transaction.

func (*StorageValue) Set

func (sv *StorageValue) Set(tx Tx, v uint32)

Set sets the value in an open db transaction.

type Tx

type Tx interface {
	Get([]byte) ([]byte, error)
	Put(k, v []byte)
	Add(Tx)
	Commit() error
	Close()
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL