db

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed   = errors.New("database closed")
	ErrNotFound = errors.New("not found")
)

Common database errors.

Functions

This section is empty.

Types

type AtomicBatch

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

AtomicBatch is a batch that writes to the database atomically.

func NewAtomicBatch

func NewAtomicBatch(db Database) *AtomicBatch

NewAtomicBatch creates a new atomic batch.

func (*AtomicBatch) Delete

func (a *AtomicBatch) Delete(key []byte) error

func (*AtomicBatch) Inner

func (a *AtomicBatch) Inner() Batch

func (*AtomicBatch) Put

func (a *AtomicBatch) Put(key, value []byte) error

func (*AtomicBatch) Replay

func (*AtomicBatch) Reset

func (a *AtomicBatch) Reset()

func (*AtomicBatch) Size

func (a *AtomicBatch) Size() int

func (*AtomicBatch) Write

func (a *AtomicBatch) Write() error

type Batch

type Batch interface {
	KeyValueWriterDeleter

	// Size returns the current size of the batch in bytes.
	Size() int

	// Write flushes the batch to the database.
	Write() error

	// Reset resets the batch to be empty.
	Reset()

	// Replay replays the operations in the batch on the provided writer.
	Replay(w KeyValueWriterDeleter) error

	// Inner returns the inner batch, if one exists.
	Inner() Batch
}

Batch is a set of operations that can be atomically committed to the database.

type Batcher

type Batcher interface {
	// NewBatch creates a new batch that can be used to perform multiple
	// operations atomically.
	NewBatch() Batch
}

Batcher is the interface for batching database operations.

type Compacter

type Compacter interface {
	// Compact flushes all writes to disk and performs any necessary cleanup.
	Compact(start []byte, limit []byte) error
}

Compacter is the interface for compacting a database.

type Database

type Database interface {
	KeyValueReader
	KeyValueWriterDeleter
	Batcher
	Iteratee
	Compacter
	io.Closer

	// HealthCheck returns nil if the database is healthy, non-nil otherwise.
	HealthCheck() error
}

Database is a key-value store that supports batch writes and iteration.

type Iteratee

type Iteratee interface {
	// NewIterator returns an iterator that will iterate over the key-value
	// pairs in the database in lexicographical order by key.
	NewIterator() Iterator

	// NewIteratorWithStart returns an iterator that will iterate over the
	// key-value pairs in the database in lexicographical order by key,
	// starting at the provided key (inclusive).
	NewIteratorWithStart(start []byte) Iterator

	// NewIteratorWithPrefix returns an iterator that will iterate over the
	// key-value pairs in the database in lexicographical order by key,
	// where each key has the provided prefix.
	NewIteratorWithPrefix(prefix []byte) Iterator

	// NewIteratorWithStartAndPrefix returns an iterator that will iterate over
	// the key-value pairs in the database in lexicographical order by key,
	// starting at the provided key (inclusive) and where each key has the
	// provided prefix.
	NewIteratorWithStartAndPrefix(start, prefix []byte) Iterator
}

Iteratee is the interface for iterating over key-value pairs.

type Iterator

type Iterator interface {
	// Next moves the iterator to the next key-value pair.
	// It returns false if the iterator is exhausted.
	Next() bool

	// Error returns any accumulated error. Exhausting all the key-value pairs
	// is not considered to be an error.
	Error() error

	// Key returns the key of the current key-value pair, or nil if done.
	Key() []byte

	// Value returns the value of the current key-value pair, or nil if done.
	Value() []byte

	// Release releases associated resources. Release should always succeed and
	// can be called multiple times without causing error.
	Release()
}

Iterator is an interface for iterating over key-value pairs.

type IteratorError

type IteratorError struct {
	Err error
}

IteratorError is a mock iterator that always returns an error.

func (*IteratorError) Error

func (i *IteratorError) Error() error

func (*IteratorError) Key

func (i *IteratorError) Key() []byte

func (*IteratorError) Next

func (i *IteratorError) Next() bool

func (*IteratorError) Release

func (i *IteratorError) Release()

func (*IteratorError) Value

func (i *IteratorError) Value() []byte

type KeyValueDeleter

type KeyValueDeleter interface {
	// Delete removes the key from the database.
	Delete(key []byte) error
}

KeyValueDeleter is the interface for deleting key-value pairs.

type KeyValueReader

type KeyValueReader interface {
	// Has returns if the database has a key with the provided value.
	Has(key []byte) (bool, error)

	// Get returns the value associated with the key.
	// If the key doesn't exist, ErrNotFound is returned.
	Get(key []byte) ([]byte, error)
}

KeyValueReader is the interface for reading key-value pairs.

type KeyValueReaderWriterDeleter

type KeyValueReaderWriterDeleter interface {
	KeyValueReader
	KeyValueWriter
	KeyValueDeleter
}

KeyValueReaderWriterDeleter is the interface for reading, writing, and deleting key-value pairs.

type KeyValueWriter

type KeyValueWriter interface {
	// Put stores the key value pair in the database.
	// If the key already exists, it will be overwritten.
	Put(key []byte, value []byte) error
}

KeyValueWriter is the interface for writing key-value pairs.

type KeyValueWriterDeleter

type KeyValueWriterDeleter interface {
	KeyValueWriter
	KeyValueDeleter
}

KeyValueWriterDeleter is the interface for writing and deleting key-value pairs.

type Pool

type Pool interface {
	// Get returns a database from the pool.
	// If there are no databases in the pool, a new one is created.
	Get() Database

	// Put returns a database to the pool.
	Put(Database)
}

Pool is a collection of databases that can be reused.

func NewPool

func NewPool(size int, generator func() Database) Pool

NewPool creates a new database pool.

Directories

Path Synopsis
Package driver provides a database driver interface for storage backends
Package driver provides a database driver interface for storage backends
state
syncapi
Package syncapi exposes the *data* formats needed by trie-/code-sync.
Package syncapi exposes the *data* formats needed by trie-/code-sync.

Jump to

Keyboard shortcuts

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