memorydb

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecodeFn

type DecodeFn func(data []byte, v any) error

type EncodeFn

type EncodeFn func(v any) ([]byte, error)

type Itr

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

func NewIterator

func NewIterator(db map[string][]byte, d DecodeFn) *Itr

func (*Itr) Close

func (it *Itr) Close() error

func (*Itr) Key

func (it *Itr) Key() []byte

func (*Itr) Next

func (it *Itr) Next()

func (*Itr) Prev

func (it *Itr) Prev()

func (*Itr) Valid

func (it *Itr) Valid() bool

func (*Itr) Value

func (it *Itr) Value(v any) error

type MemoryDB

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

MemoryDB is meant to be used as mockup for unit and integration tests where needed, not in production

func New

func New() (*MemoryDB, error)

New creates a new mock key value db that currently uses map as storage NB! map is probably not the best solution and should be replaced with binary search tree

func (*MemoryDB) Delete

func (db *MemoryDB) Delete(key []byte) error

Delete removes the key from the key-value store.

func (*MemoryDB) Find

func (db *MemoryDB) Find(key []byte) keyvaluedb.Iterator

Find returns the closest binary search match

func (*MemoryDB) First

func (db *MemoryDB) First() keyvaluedb.Iterator

First returns forward iterator to the first element in DB

func (*MemoryDB) Last

func (db *MemoryDB) Last() keyvaluedb.Iterator

Last returns reverse iterator from the last element in DB

func (*MemoryDB) MockWriteError

func (db *MemoryDB) MockWriteError(err error)

func (*MemoryDB) Read

func (db *MemoryDB) Read(key []byte, value any) (bool, error)

Read retrieves the given key if it's present in the key-value store.

func (*MemoryDB) StartTx

func (db *MemoryDB) StartTx() (keyvaluedb.DBTransaction, error)

func (*MemoryDB) Write

func (db *MemoryDB) Write(key []byte, value any) error

Write inserts the given value into the key-value store.

type Tx

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

func NewMapTx

func NewMapTx(m *MemoryDB) (*Tx, error)

func (*Tx) Commit

func (t *Tx) Commit() error

func (*Tx) Delete

func (t *Tx) Delete(key []byte) error

func (*Tx) Read

func (t *Tx) Read(key []byte, v any) (bool, error)

func (*Tx) Rollback

func (t *Tx) Rollback() error

func (*Tx) Write

func (t *Tx) Write(key []byte, value any) error

Jump to

Keyboard shortcuts

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