Documentation ¶
Index ¶
- Variables
- func FromObject(obj interface{}) ([]byte, error)
- func KVFromObject(obj interface{}) ([]byte, []byte, error)
- type MemDB
- type ResultIterator
- type Txn
- func (txn *Txn) Abort()
- func (txn *Txn) Commit()
- func (txn *Txn) Defer(fn func())
- func (txn *Txn) Delete(key []byte) error
- func (txn *Txn) DeleteAll() (int, error)
- func (txn *Txn) DeletePrefix(prefix []byte) (bool, error)
- func (txn *Txn) First(key []byte) ([]byte, interface{}, error)
- func (txn *Txn) FirstWatch(key []byte) (<-chan struct{}, []byte, interface{}, error)
- func (txn *Txn) Get(key []byte) (ResultIterator, error)
- func (txn *Txn) GetReverse(key []byte) (ResultIterator, error)
- func (txn *Txn) Insert(key []byte, value []byte) error
- func (txn *Txn) Last(key []byte) ([]byte, interface{}, error)
- func (txn *Txn) LastWatch(key []byte) (<-chan struct{}, []byte, interface{}, error)
- func (txn *Txn) LongestPrefix(key []byte) (interface{}, error)
- func (txn *Txn) LowerBound(key []byte) (ResultIterator, error)
- func (txn *Txn) ReverseLowerBound(key []byte) (ResultIterator, error)
- func (txn *Txn) Snapshot() *Txn
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when the requested item is not found ErrNotFound = fmt.Errorf("not found") )
Functions ¶
func KVFromObject ¶
Types ¶
type MemDB ¶
type MemDB struct {
// contains filtered or unexported fields
}
MemDB is an in-memory database.
MemDB provides a table abstraction to store objects (rows) with multiple indexes based on inserted values. The database makes use of immutable radix trees to provide transactions and MVCC.
type ResultIterator ¶
type ResultIterator interface { WatchCh() <-chan struct{} // Next returns the next result from the iterator. If there are no more results // nil is returned. Next() ([]byte, interface{}) }
ResultIterator is used to iterate over a list of results from a query on a table.
When a ResultIterator is created from a write transaction, the results from Next will reflect a snapshot of the table at the time the ResultIterator is created. This means that calling Insert or Delete on a transaction while iterating is allowed, but the changes made by Insert or Delete will not be observed in the results returned from subsequent calls to Next. For example if an item is deleted from the index used by the iterator it will still be returned by Next. If an item is inserted into the index used by the iterator, it will not be returned by Next. However, an iterator created after a call to Insert or Delete will reflect the modifications.
When a ResultIterator is created from a write transaction, and there are already modifications to the index used by the iterator, the modification cache of the index will be invalidated. This may result in some additional allocations if the same node in the index is modified again.
type Txn ¶
type Txn struct {
// contains filtered or unexported fields
}
Txn is a transaction against a MemDB. This can be a read or write transaction.
func (*Txn) Abort ¶
func (txn *Txn) Abort()
Abort is used to cancel this transaction. This is a noop for read transactions.
func (*Txn) Commit ¶
func (txn *Txn) Commit()
Commit is used to finalize this transaction. This is a noop for read transactions.
func (*Txn) Defer ¶
func (txn *Txn) Defer(fn func())
Defer is used to push a new arbitrary function onto a stack which gets called when a transaction is committed and finished. Deferred functions are called in LIFO order, and only invoked at the end of write transactions.
func (*Txn) Delete ¶
Delete is used to delete a single object from the given table This object must already exist in the table
func (*Txn) DeleteAll ¶
DeleteAll is used to delete all the objects in a given table matching the constraints on the index
func (*Txn) DeletePrefix ¶
DeletePrefix is used to delete an entire subtree based on a prefix. The given index must be a prefix index, and will be used to perform a scan and enumerate the set of objects to delete. These will be removed from all other indexes, and then a special prefix operation will delete the objects from the given index in an efficient subtree delete operation. This is useful when you have a very large number of objects indexed by the given index, along with a much smaller number of entries in the other indexes for those objects.
func (*Txn) First ¶
First is used to return the first matching object for the given constraints on the index
func (*Txn) FirstWatch ¶
FirstWatch is used to return the first matching object for the given constraints on the index along with the watch channel
func (*Txn) Get ¶
func (txn *Txn) Get(key []byte) (ResultIterator, error)
Get is used to construct a ResultIterator over all the rows that match the given constraints of an index.
See the documentation for ResultIterator to understand the behaviour of the returned ResultIterator.
func (*Txn) GetReverse ¶
func (txn *Txn) GetReverse(key []byte) (ResultIterator, error)
GetReverse is used to construct a Reverse ResultIterator over all the rows that match the given constraints of an index. The returned ResultIterator's Next() will return the next Previous value.
See the documentation for ResultIterator to understand the behaviour of the returned ResultIterator.
func (*Txn) Last ¶
Last is used to return the last matching object for the given constraints on the index
func (*Txn) LastWatch ¶
LastWatch is used to return the last matching object for the given constraints on the index along with the watch channel
func (*Txn) LongestPrefix ¶
LongestPrefix is used to fetch the longest prefix match for the given constraints on the index. Note that this will not work with the memdb StringFieldIndex because it adds null terminators which prevent the algorithm from correctly finding a match (it will get to right before the null and fail to find a leaf node). This should only be used where the prefix given is capable of matching indexed entries directly, which typically only applies to a custom indexer. See the unit test for an example.
func (*Txn) LowerBound ¶
func (txn *Txn) LowerBound(key []byte) (ResultIterator, error)
LowerBound is used to construct a ResultIterator over all the the range of rows that have an index value greater than or equal to the provide args. Calling this then iterating until the rows are larger than required allows range scans within an index. It is not possible to watch the resulting iterator since the radix tree doesn't efficiently allow watching on lower bound changes. The WatchCh returned will be nill and so will block forever.
See the documentation for ResultIterator to understand the behaviour of the returned ResultIterator.
func (*Txn) ReverseLowerBound ¶
func (txn *Txn) ReverseLowerBound(key []byte) (ResultIterator, error)
ReverseLowerBound is used to construct a Reverse ResultIterator over all the the range of rows that have an index value less than or equal to the provide args. Calling this then iterating until the rows are lower than required allows range scans within an index. It is not possible to watch the resulting iterator since the radix tree doesn't efficiently allow watching on lower bound changes. The WatchCh returned will be nill and so will block forever.
See the documentation for ResultIterator to understand the behaviour of the returned ResultIterator.