Documentation ¶
Index ¶
- Constants
- func BTreeDegree(degree int) func(*BucketOptions) error
- func BucketFileMultLimit(limit int) func(*Config) error
- func Developer(c *Config) error
- func Dims(dims int) func(*BucketOptions) error
- func DirPath(path string) func(*Config) error
- func ExpireTime(time time.Time) func(*EntryOptions) error
- func Geo(b *BucketOptions) error
- func GeoRangeIsInclusive(b *BucketOptions) error
- func GetEntryComparator() func(obj1, obj2 rtreego.Spatial) bool
- func InvalidTime(time time.Time) func(*EntryOptions) error
- func ManageFrequency(frequency time.Duration) func(*Config) error
- func PerformanceMonitor(c *Config) error
- func Persist(c *Config) error
- func Sync(frequency IOFrequency) func(*Config) error
- func System(b *BucketOptions) error
- func Time(b *BucketOptions) error
- func Tol(t float64) func(*EntryOptions) error
- type Bucket
- type BucketOptions
- type Config
- type Entry
- func (e *Entry) Bounds() *rtreego.Rect
- func (e *Entry) EntryDeleteStmt() []byte
- func (e *Entry) EntryInsertStmt() []byte
- func (e *Entry) ExpiresAt() time.Time
- func (e *Entry) GetKey() string
- func (e *Entry) GetValue() string
- func (e *Entry) InvalidatesAt() time.Time
- func (e *Entry) IsExpired() bool
- func (e *Entry) IsInvalid() bool
- func (e *Entry) Less(than btree.Item, itype interface{}) bool
- type EntryOptions
- type IOFrequency
- type Index
- type IndexValueType
- type Point
- type RWMode
- type RbCtx
- type Rect
- type StitchDB
- func (db *StitchDB) Close() error
- func (db *StitchDB) CreateBucket(name string, options *BucketOptions) error
- func (db *StitchDB) DropBucket(name string) error
- func (db *StitchDB) GetConfig() *Config
- func (db *StitchDB) Open() error
- func (db *StitchDB) SetConfig(config *Config)
- func (db *StitchDB) Update(bucket string, f func(t *Tx) error) error
- func (db *StitchDB) View(bucket string, f func(t *Tx) error) error
- type SystemEntry
- type SystemPerformanceEntry
- type Tx
- func (t *Tx) Ascend(index string, f func(e *Entry) bool) error
- func (t *Tx) AscendGreaterOrEqual(index string, pivot *Entry, f func(e *Entry) bool) error
- func (t *Tx) AscendLessThan(index string, pivot *Entry, f func(e *Entry) bool) error
- func (t *Tx) AscendRange(index string, greaterOrEqual *Entry, lessThan *Entry, f func(e *Entry) bool) error
- func (t *Tx) CreateIndex(pattern string, vtype IndexValueType) error
- func (t *Tx) Delete(e *Entry) (*Entry, error)
- func (t *Tx) Descend(index string, f func(e *Entry) bool) error
- func (t *Tx) DescendGreaterThan(index string, pivot *Entry, f func(e *Entry) bool) error
- func (t *Tx) DescendLessOrEqual(index string, pivot *Entry, f func(e *Entry) bool) error
- func (t *Tx) DescendRange(index string, lessOrEqual *Entry, greaterThan *Entry, f func(e *Entry) bool) error
- func (t *Tx) DropIndex(pattern string) error
- func (t *Tx) Get(e *Entry) (*Entry, error)
- func (t *Tx) Has(index string, e *Entry) (bool, error)
- func (t *Tx) Indexes() ([]string, error)
- func (t *Tx) Max(index string) (*Entry, error)
- func (t *Tx) Min(index string) (*Entry, error)
- func (t *Tx) NearestNeighbor(pt Point) (*Entry, error)
- func (t *Tx) NearestNeighbors(k int, pt Point) ([]*Entry, error)
- func (t *Tx) SearchIntersect(rbb *Rect) ([]*Entry, error)
- func (t *Tx) SearchWithinRadius(pt Point, radius float64) ([]*Entry, error)
- func (t *Tx) Set(e *Entry) (*Entry, error)
- func (t *Tx) Size(index string) (int, error)
Constants ¶
const ( //BUCKET_CONFIG_FILE is the main DB AOF BUCKET_CONFIG_FILE string = "sbkt.conf" //BUCKET_FILE_EXTENSION is the bucket AOF file extension BUCKET_FILE_EXTENSION string = ".stitch" //BUCKET_TMP_FILE_EXTENSION is the bucket AOF file extension used when replacing file BUCKET_TMP_FILE_EXTENSION string = ".stitch.tmp" )
const COMPACT_FACTOR int = 10
COMPACT_FACTOR is the Multiplier factor for to determine when to compact log.
const STITCH_VERSION string = "0.1.0"
Variables ¶
This section is empty.
Functions ¶
func BTreeDegree ¶
func BTreeDegree(degree int) func(*BucketOptions) error
BTreeDegree sets the degree of the trees ued for the bucket.
func BucketFileMultLimit ¶
BucketFileMultLimit sets the file compaction factor.
func Dims ¶
func Dims(dims int) func(*BucketOptions) error
Dims sets the number of dimensions that will be utilized.
func ExpireTime ¶
func ExpireTime(time time.Time) func(*EntryOptions) error
ExpireTime sets the time the entry will expire and enables expiration for the entry.
func GeoRangeIsInclusive ¶
func GeoRangeIsInclusive(b *BucketOptions) error
GeoRangeIsInclusive enables inclusive range checks.
func GetEntryComparator ¶
GetEntryComparator returns a function that is used by the rtree to compare entries. This function will compare on the key value (k) of the entry as a string. Todo: Maybe make the returned function an option that can be set
func InvalidTime ¶
func InvalidTime(time time.Time) func(*EntryOptions) error
InvalidTime sets the time the entry will invalidate and enables invalidation for the entry.
func ManageFrequency ¶
ManageFrequency sets the frequency at which the the db manager should run.
func PerformanceMonitor ¶
PerformanceMonitor enables the performance monitor.
func Sync ¶
func Sync(frequency IOFrequency) func(*Config) error
Sync sets the frequency at which the db file should be sync'd.
func Tol ¶
func Tol(t float64) func(*EntryOptions) error
Tol sets the tolerance (accuracy) of the geo-location for the entry primarily used to build the rtree.
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket represents a bucket in the database. Think 'table' but for key-value store.
type BucketOptions ¶
type BucketOptions struct {
// contains filtered or unexported fields
}
BucketOptions holds bucket metadata.
func NewBucketOptions ¶
func NewBucketOptions(options ...func(*BucketOptions) error) (*BucketOptions, error)
NewBucketOptions creates a new bucket options using the provided option modifiers.
func NewBucketOptionsFromStmt ¶
func NewBucketOptionsFromStmt(stmt []string) (*BucketOptions, error)
NewBucketOptionsFromStmt returns bucket options representing the options portion of the statement. Returns an error if the bucket statement could not be parsed.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds StitchDB metadata.
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry represents an item to be stored in the database.
func NewEntry ¶
NewEntry creates a new entry object with the provided values. Returns an error if the default options failed to create.
func NewEntryFromStmt ¶
NewEntryFromStmt parses the statement provided and returns an entry representation. Returns an error if the statement could not be parsed or if the resulting entry could not be created.
func NewEntryWithGeo ¶
func NewEntryWithGeo(k string, v string, options *EntryOptions) (*Entry, error)
NewEntryWithGeo creates a new entry; the entry value is expected to provide a "coords" field in the json provided. Returns an error if the default options failed to create.
func (*Entry) Bounds ¶
Bounds is used by rtree. Returns a Rect representation of the specified point using the entry options tolerance.
func (*Entry) EntryDeleteStmt ¶
EntryDeleteStmt builds and returns the delete statement for a given entity.
func (*Entry) EntryInsertStmt ¶
EntryInsertStmt builds and returns the insert statement for a given entity.
func (*Entry) InvalidatesAt ¶
InvalidatesAt returns the time that an entry will invalidate.
type EntryOptions ¶
type EntryOptions struct {
// contains filtered or unexported fields
}
EntryOptions represents the configuration for an entry determining how an entry will function within a bucket.
func NewEntryOptions ¶
func NewEntryOptions(options ...func(*EntryOptions) error) (*EntryOptions, error)
NewEntryOptions creates a new entry using the provided option modifiers.
func NewEntryOptionsFromStmt ¶
func NewEntryOptionsFromStmt(stmt []string) (*EntryOptions, error)
NewEntryOptionsFromStmt returns entry options representing the options portion of the statement. Returns an error if the entry statement could not be parsed.
type IOFrequency ¶
type IOFrequency int
IOFrequency represents the frequency in which management operations will be executed.
const ( //EACH action will take place at each commit/manage cycle EACH IOFrequency = iota //MNGFREQ action will take place at each manage cycle MNGFREQ //NONE action will never take place NONE )
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index represents an index for a bucket. Buckets can have multiple indexes but indexes cannot have entries from multiple buckets.
type IndexValueType ¶
type IndexValueType int
IndexValueType represents the type of the field that the index will be built over.
const ( //STRING_INDEX indicates data sorting should assume string. STRING_INDEX IndexValueType = iota //UINT_INDEX indicates data sorting should assume uint. UINT_INDEX //INT_INDEX indicates data sorting should assume int. INT_INDEX //FLOAT_INDEX indicates data sorting should assume float. FLOAT_INDEX )
type Point ¶
type Point []float64
Point provides an abstraction over the rtreego Point type so that dhconnelly/rtreego does not need to be included from the application using this library.
type RbCtx ¶
type RbCtx struct {
// contains filtered or unexported fields
}
RbCtx preserves the state of the tree during a transaction representing the changes made to allow for commits/rollbacks.
type Rect ¶
type Rect struct {
// contains filtered or unexported fields
}
Rect provides an abstraction over the rtreego Rect type so that dhconnelly/rtreego does not need to be included from the application using this library.
type StitchDB ¶
type StitchDB struct {
// contains filtered or unexported fields
}
StitchDB represents the database object. All operations on the database originate from this object.
func NewStitchDB ¶
NewStitchDB returns a new StitchDB with the specified configuration. Note: this function only creates the representation of the DB and does not open or start the db.
func (*StitchDB) Close ¶
Close closes each bucket including system, flushes bucket config file, and closes the file. Waits until all bucket managers have exited.
func (*StitchDB) CreateBucket ¶
func (db *StitchDB) CreateBucket(name string, options *BucketOptions) error
CreateBucket creates and opens a new bucket.
func (*StitchDB) DropBucket ¶
DropBucket closes bucket and removes the bucket from the db.
func (*StitchDB) Open ¶
Open initializes the db for use and starts the manager routine. Open opens/creates the main db append only file, parses the statements within, creates the buckets stored in the file, and opens each bucket. Returns an error if the process was not able to create the directory, failed to read the stitch db
func (*StitchDB) Update ¶
Update creates a read only transaction and passes the open transaction to the provided function. The created transaction will provide read/write access to the bucket specified by the bucket name provided. Returns an error if the db is closed or the bucket is invalid.
type SystemEntry ¶
type SystemEntry struct { InitialLoadTime time.Time `json:"InitialLoadTime"` StartUpTime time.Duration `json:"startUpTime"` LoadTime time.Duration `json:"loadTime"` BucketCount int `json:"bucketCount"` BucketList []string `json:"bucketList"` DbManagerTime time.Duration `json:"dbManagerTime"` Version string `json:"version"` }
type SystemPerformanceEntry ¶
type SystemPerformanceEntry struct { Transaction bool `json:"transaction"` Mode RWMode `json:"mode"` Bucket string `json:"bucket"` Commit bool `json:"commit"` Rollback bool `json:"rollback"` SyncTime time.Duration `json:"SyncTime"` TxTime time.Duration `json:"TxTime"` ManageTime time.Duration `json:"manageTime"` ManageSynced bool `json:"manageSynced"` ManageSyncTime time.Duration `json:"manageSyncTime"` }
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx represents the a transaction including rollback information.
func (*Tx) Ascend ¶
Ascend iterates over the items in the bucket using the specified index for each item calling the provided function f terminating only when there are no more entries in the bucket or the provided function returns false. An empty string represents no index in which case entries will use the default key ordering. Note: only the portion of the entry that the index is built with needs to be populated.
func (*Tx) AscendGreaterOrEqual ¶
AscendGreaterOrEqual iterates over the items in the bucket using the specified index for each item greater than or equal to the pivot entry calling the provided function f terminating only when there are no more entries in the bucket or the provided function returns false. An empty string represents no index in which case entries will use the default key ordering. Note: only the portion of the entry that the index is built with needs to be populated.
func (*Tx) AscendLessThan ¶
AscendLessThan iterates over the items in the bucket using the specified index for each item less than the pivot entry calling the provided function f. Iteration terminates only when there are no more entries less than pivot in the bucket or the provided function returns false. An empty string represents no index in which case entries will use the default key ordering. Note: only the portion of the entry that the index is built with needs to be populated.
func (*Tx) AscendRange ¶
func (t *Tx) AscendRange(index string, greaterOrEqual *Entry, lessThan *Entry, f func(e *Entry) bool) error
AscendRange iterates over the items in the bucket that are greater than or equal to greaterOrEqual and less than lessThan calling the provided function f. Iteration terminates only when there are no more entries in the range or the provided function returns false. An empty string represents no index in which case entries will use the default key ordering. Note: only the portion of the entry that the index is built with needs to be populated.
func (*Tx) CreateIndex ¶
func (t *Tx) CreateIndex(pattern string, vtype IndexValueType) error
CreateIndex builds an index over a field of the value of the entry. The field is identified by pattern and its type is described by vtype. Returns an error if the db or bucket is closed, the index already exists, or if an error occurred while populating the index.
func (*Tx) Delete ¶
Delete removes an entry from the bucket. If an entry is removed returns the removed entry otherwise returns nil. Returns an error if the db or bucket is closed.
func (*Tx) Descend ¶
Descend iterates over the items in the bucket using the specified index for each item calling the provided function f terminating only when there are no more entries in the bucket or the provided function returns false. An empty string represents no index in which case entries will use the default key ordering. Note: only the portion of the entry that the index is built with needs to be populated.
func (*Tx) DescendGreaterThan ¶
DescendGreaterThan iterates over the items in the bucket using the specified index for each item greater than to the pivot entry calling the provided function f terminating only when there are no more entries greater than pivot in the bucket or the provided function returns false. An empty string represents no index in which case entries will use the default key ordering. Note: only the portion of the entry that the index is built with needs to be populated.
func (*Tx) DescendLessOrEqual ¶
DescendLessOrEqual iterates over the items in the bucket using the specified index for each item less than the pivot entry calling the provided function f. Iteration terminates only when there are no more entries less than or equal to pivot in the bucket or the provided function returns false. An empty string represents no index in which case entries will use the default key ordering. Note: only the portion of the entry that the index is built with needs to be populated.
func (*Tx) DescendRange ¶
func (t *Tx) DescendRange(index string, lessOrEqual *Entry, greaterThan *Entry, f func(e *Entry) bool) error
DescendRange iterates over the items in the bucket that are less than or equal to lessOrEqual and greater than greaterThan calling the provided function f. Iteration terminates only when there are no more entries in the range or the provided function returns false. An empty string represents no index in which case entries will use the default key ordering. Note: only the portion of the entry that the index is built with needs to be populated.
func (*Tx) DropIndex ¶
DropIndex removes an index specified by pattern. Returns an error if the db or bucket is closed or if the index does not exist.
func (*Tx) Get ¶
Get returns an entry from the bucket using the default tree to search (i.e. searches on entry key). Returns nil if the the entry is invalid, expired, or not found in the bucket. Returns an error if the db or bucket is closed.
func (*Tx) Has ¶
Has chacks if an entry exists in the bucket for a given index. An empty string represents no index in which case entries will use the default key ordering.
func (*Tx) Indexes ¶
Indexes returns a slice of strings containing the names (patterns) of all indexes in the bucket.
func (*Tx) Max ¶
Max returns the maximum value entry inthe bucket for a given index. An empty string represents no index in which case the entry with the maximum key will be found.
func (*Tx) Min ¶
Min returns the minimum value entry inthe bucket for a given index. An empty string represents no index in which case the entry with the minimum key will be found.
func (*Tx) NearestNeighbor ¶
NearestNeighbor returns the closest neighbor to a given point pt. Returns an error if the bucket is not geo enabled.
func (*Tx) NearestNeighbors ¶
NearestNeighbors returns a slice of the k closest entries to a given point pt. Returns an error if the bucket is not geo enabled.
func (*Tx) SearchIntersect ¶
SearchIntersect finds entries of the bucket that fall within the bounds of the provided rectangle. Bucket must be configured for geolocation. Returns a slice containing pointers to the entries that are within the bounds of the rectangle. Returns an error if the bucket is not geo enabled.
func (*Tx) SearchWithinRadius ¶
SearchWithinRadius finds entries that are within an n-dimensional sphere centered at point pt with a radius of radius. This condition is determined by finding the Euclidean distance between the center point of the n-sphere and the point in question. The result is then determined by comparing the radius of the n-sphere and the distance between the two points. If the GeoRangeIsInclusive option is set for the bucket then the point is found the be within the n-sphere if the distance between the two points is less than the specified radius. If the GeoRangeIsInclusive option is not set then the point is found to be within the n-sphere if the distance between the two points is less than or equal to the specified radius. Returns an error if the bucket is not geo enabled.