Documentation ¶
Overview ¶
Package kv provides an abstraction over hierarchical key-value stores.
Index ¶
- Variables
- func Each(ctx context.Context, tx Tx, fnc func(k Key, v Value) error, ...) error
- func Register(reg Registration)
- func Seek(ctx context.Context, it Iterator, key Key) bool
- func Update(ctx context.Context, kv KV, update func(tx Tx) error) error
- func View(ctx context.Context, kv KV, view func(tx Tx) error) error
- type ByKey
- type Getter
- type Iterator
- type IteratorOption
- type IteratorOptionFunc
- type KV
- type Key
- type OpenPathFunc
- type Pair
- type PrefixIterator
- type Registration
- type Seeker
- type Tx
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned then a key was not found in the database. ErrNotFound = errors.New("kv: not found") // ErrReadOnly is returned when write operation is performed on read-only database or transaction. ErrReadOnly = errors.New("kv: read only") // ErrConflict is returned when write operation performed be current transaction cannot be committed // because of another concurrent write. Caller must restart the transaction. ErrConflict = errors.New("kv: read only") )
Functions ¶
func Each ¶
Each is a helper to enumerate all key-value pairs with a specific prefix. See Iterator for rules of using returned values.
func Seek ¶
Seek the iterator to a given key. If the key does not exist, the next key is used. Function returns false if there is no key greater or equal to a given one.
Types ¶
type Iterator ¶
type Iterator interface { base.Iterator // Reset the iterator to the starting state. Closed iterator can not reset. Reset() // Key return current key. Returned value will become invalid on Next or Close. // Caller should not modify or store the value - use Clone. Key() Key // Val return current value. Returned value will become invalid on Next or Close. // Caller should not modify or store the value - use Clone. Val() Value }
Iterator is an iterator over hierarchical key-value store.
func ApplyIteratorOptions ¶
func ApplyIteratorOptions(it Iterator, opts []IteratorOption) Iterator
ApplyIteratorOptions applies all iterator options.
type IteratorOption ¶
type IteratorOption interface { // ApplyKV applies option to the KV iterator. Implementation may wrap or replace the iterator. ApplyKV(it Iterator) Iterator }
IteratorOption is an additional option that affects iterator behaviour.
Implementations in generic KV package should assert for an optimized version of option (via interface assertion), and fallback to generic implementation if the store doesn't support this option natively.
type IteratorOptionFunc ¶
IteratorOptionFunc is a function type that implements IteratorOption.
func (IteratorOptionFunc) Apply ¶
func (opt IteratorOptionFunc) Apply(it Iterator) Iterator
type KV ¶
type KV interface { base.DB Tx(ctx context.Context, rw bool) (Tx, error) View(ctx context.Context, fn func(tx Tx) error) error Update(ctx context.Context, fn func(tx Tx) error) error }
KV is an interface for hierarchical key-value databases.
type Key ¶
type Key [][]byte
Key is a hierarchical binary key used in a database.
func (Key) Append ¶
Append key parts and return a new value. Value is not a deep copy, use Clone for this.
func (Key) AppendBytes ¶
AppendBytes is the same like Append, but accepts bytes slices.
type OpenPathFunc ¶
OpenPathFunc is a function for opening a database given a path.
type PrefixIterator ¶
type PrefixIterator interface { Iterator // WithPrefix implements WithPrefix iterator option. // Current iterator will be replaced with a new one and must not be used after this call. WithPrefix(pref Key) Iterator }
PrefixIterator is an Iterator optimization to support WithPrefix option.
type Registration ¶
type Registration struct { base.Registration OpenPath OpenPathFunc }
Registration is an information about the database driver.
func ByName ¶
func ByName(name string) *Registration
ByName returns a registered database driver by it's name.
type Tx ¶
type Tx interface { base.Tx Getter // GetBatch fetches values for multiple keys from the database. // Nil element in the slice indicates that key does not exists. GetBatch(ctx context.Context, keys []Key) ([]Value, error) // Put writes a key-value pair to the database. // New value will immediately be visible by Get on the same Tx, // but implementation might buffer the write until transaction is committed. Put(ctx context.Context, k Key, v Value) error // Del removes the key from the database. See Put for consistency guaranties. Del(ctx context.Context, k Key) error // Scan starts iteration over key-value pairs. Returned results are affected by IteratorOption. Scan(ctx context.Context, opts ...IteratorOption) Iterator }
Tx is a transaction over hierarchical key-value store.