Documentation
¶
Index ¶
- Variables
- type CompoundIndex
- type ConditionalIndex
- type ConditionalIndexFunc
- type DBSchema
- type FieldSetIndex
- type IndexSchema
- type Indexer
- type MemDB
- type MultiIndexer
- type PrefixIndexer
- type ResultIterator
- type SingleIndexer
- type StringFieldIndex
- type StringMapFieldIndex
- type StringSliceFieldIndex
- type TableSchema
- type Txn
- func (txn *Txn) Abort()
- func (txn *Txn) Commit()
- func (txn *Txn) Defer(fn func())
- func (txn *Txn) Delete(table string, obj interface{}) error
- func (txn *Txn) DeleteAll(table, index string, args ...interface{}) (int, error)
- func (txn *Txn) First(table, index string, args ...interface{}) (interface{}, error)
- func (txn *Txn) Get(table, index string, args ...interface{}) (ResultIterator, error)
- func (txn *Txn) Insert(table string, obj interface{}) error
- func (txn *Txn) LongestPrefix(table, index string, args ...interface{}) (interface{}, error)
- type UUIDFieldIndex
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type CompoundIndex ¶
type CompoundIndex struct {
Indexes []Indexer
// AllowMissing results in an index based on only the indexers
// that return data. If true, you may end up with 2/3 columns
// indexed which might be useful for an index scan. Otherwise,
// the CompoundIndex requires all indexers to be satisfied.
AllowMissing bool
}
CompoundIndex is used to build an index using multiple sub-indexes Prefix based iteration is supported as long as the appropriate prefix of indexers support it. All sub-indexers are only assumed to expect a single argument.
func (*CompoundIndex) FromArgs ¶
func (c *CompoundIndex) FromArgs(args ...interface{}) ([]byte, error)
func (*CompoundIndex) FromObject ¶
func (c *CompoundIndex) FromObject(raw interface{}) (bool, []byte, error)
func (*CompoundIndex) PrefixFromArgs ¶
func (c *CompoundIndex) PrefixFromArgs(args ...interface{}) ([]byte, error)
type ConditionalIndex ¶
type ConditionalIndex struct {
Conditional ConditionalIndexFunc
}
ConditionalIndex builds an index based on a condition specified by a passed user function. This function may examine the passed object and return a boolean to encapsulate an arbitrarily complex conditional.
func (*ConditionalIndex) FromArgs ¶
func (c *ConditionalIndex) FromArgs(args ...interface{}) ([]byte, error)
func (*ConditionalIndex) FromObject ¶
func (c *ConditionalIndex) FromObject(obj interface{}) (bool, []byte, error)
type ConditionalIndexFunc ¶
ConditionalIndexFunc is the required function interface for a ConditionalIndex.
type DBSchema ¶
type DBSchema struct {
Tables map[string]*TableSchema
}
DBSchema contains the full database schema used for MemDB
type FieldSetIndex ¶
type FieldSetIndex struct {
Field string
}
FieldSetIndex is used to extract a field from an object using reflection and builds an index on whether the field is set by comparing it against its type's nil value.
func (*FieldSetIndex) FromArgs ¶
func (f *FieldSetIndex) FromArgs(args ...interface{}) ([]byte, error)
func (*FieldSetIndex) FromObject ¶
func (f *FieldSetIndex) FromObject(obj interface{}) (bool, []byte, error)
type IndexSchema ¶
IndexSchema contains the schema for an index
func (*IndexSchema) Validate ¶
func (s *IndexSchema) Validate() error
type Indexer ¶
type Indexer interface {
// ExactFromArgs is used to build an exact index lookup
// based on arguments
FromArgs(args ...interface{}) ([]byte, error)
}
Indexer is an interface used for defining indexes
type MemDB ¶
type MemDB struct {
// contains filtered or unexported fields
}
MemDB is an in-memory database. It provides a table abstraction, which is used to store objects (rows) with multiple indexes based on values. The database makes use of immutable radix trees to provide transactions and MVCC.
type MultiIndexer ¶
type MultiIndexer interface {
// FromObject is used to extract index values from an
// object or to indicate that the index value is missing.
FromObject(raw interface{}) (bool, [][]byte, error)
}
MultiIndexer is an interface used for defining indexes generating multiple entries per object
type PrefixIndexer ¶
type PrefixIndexer interface {
// PrefixFromArgs returns a prefix that should be used
// for scanning based on the arguments
PrefixFromArgs(args ...interface{}) ([]byte, error)
}
PrefixIndexer can optionally be implemented for any indexes that support prefix based iteration. This may not apply to all indexes.
type ResultIterator ¶
type ResultIterator interface {
Next() interface{}
}
ResultIterator is used to iterate over a list of results from a Get query on a table.
type SingleIndexer ¶
type SingleIndexer interface {
// FromObject is used to extract an index value from an
// object or to indicate that the index value is missing.
FromObject(raw interface{}) (bool, []byte, error)
}
SingleIndexer is an interface used for defining indexes generating a single entry per object
type StringFieldIndex ¶
StringFieldIndex is used to extract a field from an object using reflection and builds an index on that field.
func (*StringFieldIndex) FromArgs ¶
func (s *StringFieldIndex) FromArgs(args ...interface{}) ([]byte, error)
func (*StringFieldIndex) FromObject ¶
func (s *StringFieldIndex) FromObject(obj interface{}) (bool, []byte, error)
func (*StringFieldIndex) PrefixFromArgs ¶
func (s *StringFieldIndex) PrefixFromArgs(args ...interface{}) ([]byte, error)
type StringMapFieldIndex ¶
StringMapFieldIndex is used to extract a field of type map[string]string from an object using reflection and builds an index on that field.
func (*StringMapFieldIndex) FromArgs ¶
func (s *StringMapFieldIndex) FromArgs(args ...interface{}) ([]byte, error)
func (*StringMapFieldIndex) FromObject ¶
func (s *StringMapFieldIndex) FromObject(obj interface{}) (bool, [][]byte, error)
type StringSliceFieldIndex ¶
StringSliceFieldIndex is used to extract a field from an object using reflection and builds an index on that field.
func (*StringSliceFieldIndex) FromArgs ¶
func (s *StringSliceFieldIndex) FromArgs(args ...interface{}) ([]byte, error)
func (*StringSliceFieldIndex) FromObject ¶
func (s *StringSliceFieldIndex) FromObject(obj interface{}) (bool, [][]byte, error)
func (*StringSliceFieldIndex) PrefixFromArgs ¶
func (s *StringSliceFieldIndex) PrefixFromArgs(args ...interface{}) ([]byte, error)
type TableSchema ¶
type TableSchema struct {
Name string
Indexes map[string]*IndexSchema
}
TableSchema contains the schema for a single table
func (*TableSchema) Validate ¶
func (s *TableSchema) Validate() error
Validate is used to validate the table schema
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) First ¶
First is used to return the first matching object for the given constraints on the index
func (*Txn) Get ¶
func (txn *Txn) Get(table, index string, args ...interface{}) (ResultIterator, error)
Get is used to construct a ResultIterator over all the rows that match the given constraints of an index.
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.
type UUIDFieldIndex ¶
type UUIDFieldIndex struct {
Field string
}
UUIDFieldIndex is used to extract a field from an object using reflection and builds an index on that field by treating it as a UUID. This is an optimization to using a StringFieldIndex as the UUID can be more compactly represented in byte form.
func (*UUIDFieldIndex) FromArgs ¶
func (u *UUIDFieldIndex) FromArgs(args ...interface{}) ([]byte, error)
func (*UUIDFieldIndex) FromObject ¶
func (u *UUIDFieldIndex) FromObject(obj interface{}) (bool, []byte, error)
func (*UUIDFieldIndex) PrefixFromArgs ¶
func (u *UUIDFieldIndex) PrefixFromArgs(args ...interface{}) ([]byte, error)