Documentation
¶
Overview ¶
Package memdb provides a generic, concurrency-safe, copy-on-write in-memory store following the point-in-time snapshot pattern. Readers obtain lock-free immutable views, while writers mutate atomically through transactions or direct mutation methods.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyPrefix is returned by GetByPrefix when prefix is empty. ErrEmptyPrefix = errors.New("memdb: prefix cannot be empty") // ErrNotFound is returned by GetByPrefix when no item matches prefix. ErrNotFound = errors.New("memdb: not found") // ErrAmbiguous is returned by GetByPrefix when multiple items match prefix. ErrAmbiguous = errors.New("memdb: multiple items match prefix") )
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB[T any] struct { // contains filtered or unexported fields }
DB is a generic, concurrency-safe, copy-on-write in-memory store.
func New ¶
New creates a new DB where keyFn extracts the unique string key from T. Items in All() are kept sorted by key ascending.
func (*DB[T]) Replace ¶
func (db *DB[T]) Replace(items ...T)
Replace atomically replaces all items in the DB with items.
func (*DB[T]) Save ¶
func (db *DB[T]) Save(items ...T)
Save inserts or updates one or more items atomically.
type Txn ¶
type Txn[T any] struct { // contains filtered or unexported fields }
Txn represents an isolated write transaction.
type View ¶
type View[T any] struct { // contains filtered or unexported fields }
View represents a consistent point-in-time snapshot.
func (*View[T]) All ¶
func (v *View[T]) All() []T
All returns a slice of all items sorted by key ascending.
func (*View[T]) GetByPrefix ¶
GetByPrefix resolves an item by prefix. Returns ErrEmptyPrefix if prefix is empty. If an exact match exists, it is returned immediately. If multiple items match prefix, ErrAmbiguous is returned. If no item matches prefix, ErrNotFound is returned.