index

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2017 License: MIT Imports: 4 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 uses 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")
)

Functions

This section is empty.

Types

type Index

type Index interface {
	Add(value []byte, targetID []byte) error
	Remove(value []byte) error
	RemoveID(id []byte) error
	Get(value []byte) []byte
	All(value []byte, opts *Options) ([][]byte, error)
	AllRecords(opts *Options) ([][]byte, error)
	Range(min []byte, max []byte, opts *Options) ([][]byte, error)
	Prefix(prefix []byte, opts *Options) ([][]byte, error)
}

Index interface

type ListIndex

type ListIndex struct {
	Parent      *bolt.Bucket
	IndexBucket *bolt.Bucket
	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(newValue []byte, targetID []byte) error

Add a value to the list index

func (*ListIndex) All

func (idx *ListIndex) All(value []byte, opts *Options) ([][]byte, error)

All the IDs corresponding to the given value

func (*ListIndex) AllRecords

func (idx *ListIndex) AllRecords(opts *Options) ([][]byte, error)

AllRecords returns all the IDs of this index

func (*ListIndex) Get

func (idx *ListIndex) Get(value []byte) []byte

Get the first ID corresponding to the given value

func (*ListIndex) Prefix

func (idx *ListIndex) Prefix(prefix []byte, opts *Options) ([][]byte, error)

Prefix returns the ids whose values have the given prefix.

func (*ListIndex) Range

func (idx *ListIndex) Range(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(value []byte) error

Remove a value from the unique index

func (*ListIndex) RemoveID

func (idx *ListIndex) RemoveID(targetID []byte) error

RemoveID removes an ID from the list index

type Options

type Options struct {
	Limit   int
	Skip    int
	Reverse bool
}

Options are used to customize queries

func NewOptions

func NewOptions() *Options

NewOptions creates initialized Options

type UniqueIndex

type UniqueIndex struct {
	Parent      *bolt.Bucket
	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(value []byte, targetID []byte) error

Add a value to the unique index

func (*UniqueIndex) All

func (idx *UniqueIndex) All(value []byte, opts *Options) ([][]byte, error)

All returns all the ids corresponding to the given value

func (*UniqueIndex) AllRecords

func (idx *UniqueIndex) AllRecords(opts *Options) ([][]byte, error)

AllRecords returns all the IDs of this index

func (*UniqueIndex) Get

func (idx *UniqueIndex) Get(value []byte) []byte

Get the id corresponding to the given value

func (*UniqueIndex) Prefix

func (idx *UniqueIndex) Prefix(prefix []byte, opts *Options) ([][]byte, error)

Prefix returns the ids whose values have the given prefix.

func (*UniqueIndex) Range

func (idx *UniqueIndex) Range(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(value []byte) error

Remove a value from the unique index

func (*UniqueIndex) RemoveID

func (idx *UniqueIndex) RemoveID(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