index

package
v6.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package index contains Index engines used to store values and their corresponding IDs

Index

Constants

This section is empty.

Variables

View Source
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

func NewIDIndex(parent *bolt.Bucket, indexName []byte) (*IDIndex, error)

NewIDIndex returns an ID index backed by parent.

func (*IDIndex) Add

func (idx *IDIndex) Add(ctx context.Context, value []byte, targetID []byte) error

Add validates a primary-key index entry; the primary record bucket stores the mapping.

func (*IDIndex) All

func (idx *IDIndex) All(ctx context.Context, value []byte, opts *Options) ([][]byte, error)

All returns all the ids corresponding to the given value

func (*IDIndex) AllRecords

func (idx *IDIndex) AllRecords(ctx context.Context, opts *Options) ([][]byte, error)

AllRecords returns all the IDs of this index

func (*IDIndex) Get

func (idx *IDIndex) Get(ctx context.Context, value []byte) ([]byte, error)

Get returns the ID corresponding to value.

func (*IDIndex) Prefix

func (idx *IDIndex) Prefix(ctx context.Context, prefix []byte, opts *Options) ([][]byte, error)

Prefix returns the ids whose values have the given prefix.

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

func (*IDIndex) Remove

func (idx *IDIndex) Remove(ctx context.Context, value []byte) error

Remove validates context for an ID-index removal; primary records are removed by the store.

func (*IDIndex) RemoveID

func (idx *IDIndex) RemoveID(ctx context.Context, id []byte) error

RemoveID removes an ID from the unique index

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

func NewListIndex(parent *bolt.Bucket, indexName []byte) (*ListIndex, error)

NewListIndex loads a ListIndex

func (*ListIndex) Add

func (idx *ListIndex) Add(ctx context.Context, newValue []byte, targetID []byte) error

Add a value to the list index

func (*ListIndex) All

func (idx *ListIndex) All(ctx context.Context, value []byte, opts *Options) ([][]byte, error)

All the IDs corresponding to the given value

func (*ListIndex) AllRecords

func (idx *ListIndex) AllRecords(ctx context.Context, opts *Options) ([][]byte, error)

AllRecords returns all the IDs of this index

func (*ListIndex) Get

func (idx *ListIndex) Get(ctx context.Context, value []byte) ([]byte, error)

Get the first ID corresponding to the given value

func (*ListIndex) Prefix

func (idx *ListIndex) Prefix(ctx context.Context, prefix []byte, opts *Options) ([][]byte, error)

Prefix returns the ids whose values have the given prefix.

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

func (*ListIndex) Remove

func (idx *ListIndex) Remove(ctx context.Context, value []byte) error

Remove a value from the unique index

func (*ListIndex) RemoveID

func (idx *ListIndex) RemoveID(ctx context.Context, targetID []byte) error

RemoveID removes an ID from the list index

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) Add

func (idx *UniqueIndex) Add(ctx context.Context, value []byte, targetID []byte) error

Add a value to the unique index

func (*UniqueIndex) All

func (idx *UniqueIndex) All(ctx context.Context, value []byte, opts *Options) ([][]byte, error)

All returns all the ids corresponding to the given value

func (*UniqueIndex) AllRecords

func (idx *UniqueIndex) AllRecords(ctx context.Context, opts *Options) ([][]byte, error)

AllRecords returns all the IDs of this index

func (*UniqueIndex) Get

func (idx *UniqueIndex) Get(ctx context.Context, value []byte) ([]byte, error)

Get the id corresponding to the given value

func (*UniqueIndex) Prefix

func (idx *UniqueIndex) Prefix(ctx context.Context, prefix []byte, opts *Options) ([][]byte, error)

Prefix returns the ids whose values have the given prefix.

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

func (*UniqueIndex) Remove

func (idx *UniqueIndex) Remove(ctx context.Context, value []byte) error

Remove a value from the unique index

func (*UniqueIndex) RemoveID

func (idx *UniqueIndex) RemoveID(ctx context.Context, id []byte) error

RemoveID removes an ID from the unique index

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL