Documentation ¶
Overview ¶
Package flat provides an abstraction over flat key-value stores.
Index ¶
- Variables
- func Each(ctx context.Context, tx Tx, fnc func(k Key, v Value) error, ...) error
- func KeyUnescape(k Key) kv.Key
- 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 Upgrade(flat KV) kv.KV
- func UpgradeOpenPath(open OpenPathFunc) kv.OpenPathFunc
- func View(ctx context.Context, kv KV, view func(tx Tx) error) error
- 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 = kv.ErrNotFound // ErrReadOnly is returned when write operation is performed on read-only database or transaction. ErrReadOnly = kv.ErrReadOnly // ErrConflict is returned when write operation performed be current transaction cannot be committed // because of another concurrent write. Caller must restart the transaction. ErrConflict = kv.ErrConflict )
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 KeyUnescape ¶ added in v0.2.0
KeyUnescape converts flat Key into kv.Key.
func Seek ¶ added in v0.2.0
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.
func Update ¶
Update is a helper to open a read-write transaction and update the database. The update function may be called multiple times in case of conflicts with other writes.
func UpgradeOpenPath ¶
func UpgradeOpenPath(open OpenPathFunc) kv.OpenPathFunc
UpgradeOpenPath automatically upgrades flat KV to hierarchical KV on open.
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 ¶ added in v0.2.0
func ApplyIteratorOptions(it Iterator, opts []IteratorOption) Iterator
ApplyIteratorOptions applies all iterator options.
type IteratorOption ¶ added in v0.2.0
type IteratorOption interface { // ApplyFlat option to the flat KV iterator. Implementation may wrap or replace the iterator. ApplyFlat(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 ¶ added in v0.2.0
IteratorOptionFunc is a function type that implements IteratorOption.
func (IteratorOptionFunc) ApplyFlat ¶ added in v0.2.0
func (opt IteratorOptionFunc) ApplyFlat(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 flat key-value databases.
type Key ¶
type Key []byte
Key is a flat binary key used in a database.
type OpenPathFunc ¶
OpenPathFunc is a function for opening a database given a path.
type PrefixIterator ¶ added in v0.2.0
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 flat key-value store.