Documentation
¶
Overview ¶
Package index contains Index engines used to store values and their corresponding IDs
Index ¶
- Variables
- type IDIndex
- func (idx *IDIndex) Add(ctx context.Context, value []byte, targetID []byte) error
- func (idx *IDIndex) All(ctx context.Context, value []byte, opts *Options) ([][]byte, error)
- func (idx *IDIndex) AllRecords(ctx context.Context, opts *Options) ([][]byte, error)
- func (idx *IDIndex) Get(ctx context.Context, value []byte) ([]byte, error)
- func (idx *IDIndex) Prefix(ctx context.Context, prefix []byte, opts *Options) ([][]byte, error)
- func (idx *IDIndex) Range(ctx context.Context, min []byte, max []byte, opts *Options) ([][]byte, error)
- func (idx *IDIndex) Remove(ctx context.Context, value []byte) error
- func (idx *IDIndex) RemoveID(ctx context.Context, id []byte) error
- type Index
- type ListIndex
- func (idx *ListIndex) Add(ctx context.Context, newValue []byte, targetID []byte) error
- func (idx *ListIndex) All(ctx context.Context, value []byte, opts *Options) ([][]byte, error)
- func (idx *ListIndex) AllRecords(ctx context.Context, opts *Options) ([][]byte, error)
- func (idx *ListIndex) Get(ctx context.Context, value []byte) ([]byte, error)
- func (idx *ListIndex) Prefix(ctx context.Context, prefix []byte, opts *Options) ([][]byte, error)
- func (idx *ListIndex) Range(ctx context.Context, min []byte, max []byte, opts *Options) ([][]byte, error)
- func (idx *ListIndex) Remove(ctx context.Context, value []byte) error
- func (idx *ListIndex) RemoveID(ctx context.Context, targetID []byte) error
- type Options
- type UniqueIndex
- func (idx *UniqueIndex) Add(ctx context.Context, value []byte, targetID []byte) error
- func (idx *UniqueIndex) All(ctx context.Context, value []byte, opts *Options) ([][]byte, error)
- func (idx *UniqueIndex) AllRecords(ctx context.Context, opts *Options) ([][]byte, error)
- func (idx *UniqueIndex) Get(ctx context.Context, value []byte) ([]byte, error)
- func (idx *UniqueIndex) Prefix(ctx context.Context, prefix []byte, opts *Options) ([][]byte, error)
- func (idx *UniqueIndex) Range(ctx context.Context, min []byte, max []byte, opts *Options) ([][]byte, error)
- func (idx *UniqueIndex) Remove(ctx context.Context, value []byte) error
- func (idx *UniqueIndex) RemoveID(ctx context.Context, id []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when the specified record is not saved in the bucket. ErrNotFound = errors.New("not found") // ErrAlreadyExists is returned when trying to set an existing value on a field that has a unique index. ErrAlreadyExists = errors.New("already exists") // ErrNilParam is returned when the specified param is expected to be not nil. ErrNilParam = errors.New("param must not be nil") // ErrNilContext is returned when a nil context.Context is passed to an operation that requires a context. ErrNilContext = errors.New("context must not be nil") )
Functions ¶
This section is empty.
Types ¶
type IDIndex ¶
type IDIndex struct {
// IndexBucket stores the encoded primary-key entries.
IndexBucket *bolt.Bucket
}
IDIndex is an index that references unique values and the corresponding ID.
func NewIDIndex ¶
NewIDIndex returns an ID index backed by parent.
func (*IDIndex) Add ¶
Add validates a primary-key index entry; the primary record bucket stores the mapping.
func (*IDIndex) AllRecords ¶
AllRecords returns all the IDs of this index
func (*IDIndex) Range ¶
func (idx *IDIndex) Range(ctx context.Context, min []byte, max []byte, opts *Options) ([][]byte, error)
Range returns the ids corresponding to the given range of values
type Index ¶
type Index interface {
// Add associates value with targetID.
Add(ctx context.Context, value []byte, targetID []byte) error
// Remove deletes all index entries for value.
Remove(ctx context.Context, value []byte) error
// RemoveID deletes index entries that reference id.
RemoveID(ctx context.Context, id []byte) error
// Get returns the first ID associated with value.
Get(ctx context.Context, value []byte) ([]byte, error)
// All returns IDs associated with value using opts.
All(ctx context.Context, value []byte, opts *Options) ([][]byte, error)
// AllRecords returns all indexed IDs using opts.
AllRecords(ctx context.Context, opts *Options) ([][]byte, error)
// Range returns IDs whose values fall within the inclusive range.
Range(ctx context.Context, min []byte, max []byte, opts *Options) ([][]byte, error)
// Prefix returns IDs whose values begin with prefix.
Prefix(ctx context.Context, prefix []byte, opts *Options) ([][]byte, error)
}
Index maps encoded field values to encoded record IDs.
type ListIndex ¶
type ListIndex struct {
// Parent contains the record bucket and its index buckets.
Parent *bolt.Bucket
// IndexBucket stores value-to-ID list entries.
IndexBucket *bolt.Bucket
// IDs tracks indexed IDs for cleanup and full-record traversal.
IDs *UniqueIndex
}
ListIndex is an index that references values and the corresponding IDs.
func NewListIndex ¶
NewListIndex loads a ListIndex
func (*ListIndex) AllRecords ¶
AllRecords returns all the IDs of this index
func (*ListIndex) Range ¶
func (idx *ListIndex) Range(ctx context.Context, min []byte, max []byte, opts *Options) ([][]byte, error)
Range returns the ids corresponding to the given range of values
type Options ¶
type Options struct {
// Limit is the maximum number of results; a negative value means unlimited.
Limit int
// Skip is the number of matching results to omit.
Skip int
// Reverse requests reverse index traversal.
Reverse bool
}
Options controls index result pagination and ordering.
func NewOptions ¶
func NewOptions() *Options
NewOptions returns Options initialized with no result limit.
type UniqueIndex ¶
type UniqueIndex struct {
// Parent contains the record bucket and its index buckets.
Parent *bolt.Bucket
// IndexBucket stores one encoded ID per unique value.
IndexBucket *bolt.Bucket
}
UniqueIndex is an index that references unique values and the corresponding ID.
func NewUniqueIndex ¶
func NewUniqueIndex(parent *bolt.Bucket, indexName []byte) (*UniqueIndex, error)
NewUniqueIndex loads a UniqueIndex
func (*UniqueIndex) AllRecords ¶
AllRecords returns all the IDs of this index
func (*UniqueIndex) Range ¶
func (idx *UniqueIndex) Range(ctx context.Context, min []byte, max []byte, opts *Options) ([][]byte, error)
Range returns the ids corresponding to the given range of values