memorydb

package
v0.0.0-...-fb9d71b Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package memorydb provides an implementation of the sortedkv interfaces. The main type, Database, is an in-memory key-value store. Since the database is not persistent, the package is not suited for production use, and more suited for simplifying tests and mockups. The database is thread-safe.

Constructors

The NewDatabase() constructor creates a new empty database. The FromData() constructor takes a key-value mapping and uses that as the database's contents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromData

func FromData(data map[string]string) sortedkv.Database

FromData creates a Database from a map of values. The provided data will not be cloned. If data is nil, an empty database is created.

func NewDatabase

func NewDatabase() sortedkv.Database

NewDatabase creates a new, empty Database.

Types

type Batch

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

Batch represents a batch and implements the batch interface.

func (*Batch) Apply

func (b *Batch) Apply() error

Apply applies the batch to the database.

func (*Batch) Delete

func (b *Batch) Delete(key string) error

Delete deletes a value from the batch.

func (*Batch) Put

func (b *Batch) Put(key string, value string) error

Put puts a new value in the batch.

func (*Batch) PutBytes

func (b *Batch) PutBytes(key string, value []byte) error

PutBytes puts a new byte slice into the batch.

func (*Batch) Reset

func (b *Batch) Reset()

Reset resets the batch.

type Database

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

Database implements the Database interface and stores the values in memory.

func (*Database) Close

func (d *Database) Close() error

Close clears the database.

func (*Database) Delete

func (d *Database) Delete(key string) error

Delete deletes a key from the database.

func (*Database) Get

func (d *Database) Get(key string) (string, error)

Get returns a value to a key.

func (*Database) GetBytes

func (d *Database) GetBytes(key string) ([]byte, error)

GetBytes returns a value to a key in bytes.

func (*Database) Has

func (d *Database) Has(key string) (bool, error)

Has returns true if the memorydb contains a key.

func (*Database) NewBatch

func (d *Database) NewBatch() sortedkv.Batch

NewBatch creates a new batch.

func (*Database) NewIterator

func (d *Database) NewIterator() sortedkv.Iterator

NewIterator creates a new iterator.

func (*Database) NewIteratorWithPrefix

func (d *Database) NewIteratorWithPrefix(prefix string) sortedkv.Iterator

NewIteratorWithPrefix creates a new iterator for a given prefix.

func (*Database) NewIteratorWithRange

func (d *Database) NewIteratorWithRange(start string, end string) sortedkv.Iterator

NewIteratorWithRange creates a new iterator based on a given range.

func (*Database) Put

func (d *Database) Put(key string, value string) error

Put saves a value under a key.

func (*Database) PutBytes

func (d *Database) PutBytes(key string, value []byte) error

PutBytes saves a bytes value under a key.

type Iterator

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

Iterator provides an iterator over a key range.

func (*Iterator) Close

func (i *Iterator) Close() error

Close closes this iterator.

func (*Iterator) Key

func (i *Iterator) Key() string

Key returns the key of the current element.

func (*Iterator) Next

func (i *Iterator) Next() bool

Next returns true if the iterator has a next element.

func (*Iterator) Value

func (i *Iterator) Value() string

Value returns the value of the current element.

func (*Iterator) ValueBytes

func (i *Iterator) ValueBytes() []byte

ValueBytes returns the value converted to bytes of the current element.

Jump to

Keyboard shortcuts

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