1package datastore23import (4 "errors"5 "strings"6)78var (9 ErrEmptyQueryIndexName = errors.New("query index name is empty")10 ErrInvalidQueryOffset = errors.New("minimum allowed query offset is 0")11 ErrInvalidQuerySize = errors.New("minimum allowed query size is 1")12)1314// QueryOption configures queries.15type QueryOption func(*Query) error1617// WithOffset assigns the offset or position of the first record that query must return.18// The minimum allowed offset is 0.19func WithOffset(offset int) QueryOption {20 return func(q *Query) error {21 if offset < 0 {22 return ErrInvalidQueryOffset23 }2425 q.offset = offset26 return nil27 }28}2930// WithSize assigns the maximum number of records that query can return.31// The minimum allowed size is 1.32func WithSize(size int) QueryOption {33 return func(q *Query) error {34 if size < 1 {35 return ErrInvalidQuerySize36 }3738 q.size = size39 return nil40 }41}4243// UseIndex assigns the index that the query must use to get the records.44// Using an index requires a key value to locate the records within the index.45func UseIndex(name, key string) QueryOption {46 return func(q *Query) error {47 q.indexName = strings.TrimSpace(name)48 if q.indexName == "" {49 return ErrEmptyQueryIndexName50 }5152 q.indexKey = key53 return nil54 }55}56Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.