query

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: Apache-2.0, MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constraint

type Constraint func(routing.Iterator) Selector

Constraints restrict the results of a selector to a subset of current matches.

func First

func First() Constraint

First restricts the selection to a single item.

func Limit

func Limit(n int) Constraint

Limit restricts the selection to n items.

func To

func To(index routing.Index) Constraint

To restricts the selection to items less-than-or-equal-to the index. Use with From to implement range queries.

func Where

func Where(match Matcher) Constraint

Where restricts a selection according to some arbitrary criteria. It is effectively a filter.

func While

func While(predicate Matcher) Constraint

While iterates over a selection until the predicate returns boolean false.

type Matcher

type Matcher interface {
	// Match returns true if the supplied record matches
	// some arbitrary criteria.  It is used to implement
	// filtering.  See:  Where.
	Match(routing.Record) bool
}

Matcher reports whether a routing record matches some arbitrary criteria.

type Query

type Query struct {
	routing.Snapshot
}

func (Query) Iter

func (q Query) Iter(sel Selector, cs ...Constraint) (routing.Iterator, error)

Iter traverses the snapshot in lexicographical order, unless q is the result of having called Reverse() on a non-reversed Query.

func (Query) Lookup

func (q Query) Lookup(sel Selector, cs ...Constraint) (routing.Record, error)

Lookup returns the first record in the selection. The returned record is nil if the selection is empty.

func (Query) Reverse

func (q Query) Reverse() Query

Reverse returns a Query that traverses the snapshot in reverse lexicographical-order. Calling Reverse on the resulting query undoes the reversal.

type Selector

type Selector func(routing.Snapshot) (routing.Iterator, error)

Selector specifies an iteration strategy over a set of routing records.

func All

func All() Selector

All selects all records in the routing table.

func Failure

func Failure(err error) Selector

Failure returns a Selector that fails with the supplied error.

func Failuref

func Failuref(format string, args ...any) Selector

Failuref formats a string using fmt.Errorf and passes the result to Failure.

func From

func From(index routing.Index) Selector

Select all records, beginning with the indexed record, and iterating in lexicographic order.

func Range

func Range(min, max routing.Index) Selector

Range selects all records in the interval [min, max].

func Select

func Select(index routing.Index) Selector

Select all records matching the index.

func (Selector) Bind

func (selection Selector) Bind(f Constraint) Selector

Bind a constraint to the selector, causing it to select a subset of the current selection.

Jump to

Keyboard shortcuts

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