option

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 1 Imported by: 8

README

Option

Query options for the data library. Each option is a small value type implementing the Option interface; together they describe optional query behavior (sorting, row limits, field projection, case sensitivity) without binding to any specific database.

These types only encapsulate intent. They contain no query logic — it is each database adapter's job to inspect the options it receives and translate them into its own query engine. See the adapter packages (data-mongo, data-slice) for how each is interpreted.

What matters here

  • FirstRow() means "return only the first matching row" — it is NOT a pagination offset. FirstRowOption is an empty struct and carries no row number; adapters translate it to a limit of one row. The name misleads: use MaxRows(n) to cap results, and do not expect FirstRow to skip to an arbitrary row.

  • Each option carries a TypeXxx string token returned by OptionType(). Adapters switch on the concrete type (not the token) to apply each option; the token exists mainly for debugging. When adding a new option, follow the existing trio: a TypeXxx constant, an XxxOption value type, and a lowercase constructor returning Option.

  • MaxRows(0) means "no limit", not "no rows". Negative values are clamped to zero on the way in and on the way out, so an adapter never sees a meaningless limit — mongodb, for one, reads a raw -1 as "return one row, then close the cursor". Zero doubles as the zero value of MaxRowsOption, so an uninitialized option is harmless. Use FirstRow() to request a single row.

  • Read a sort direction through IsDescending() / IsAscending(), not the Direction field. The field is exported and unvalidated, so it may hold a typo, a lowercase variant, or the empty string of a zero-value SortOption. The accessors treat only the exact SortDirectionDescending token as descending and default everything else to ascending, so adapters cannot disagree about a malformed value.

  • Fields is copy-in / copy-out. The constructor clones the variadic slice and the accessor clones on return, so a caller's later writes to its own slice cannot rewrite a live option, and an adapter cannot corrupt the option it was handed.

  • An adapter may silently ignore an option it doesn't support. There is no central registry forcing every backend to honor every option, so a query relying on CaseSensitive or Fields can behave differently across backends. Confirm support in the specific adapter.

Documentation

Overview

Package option provides an interface for query options that can be used to modify database queries.

Index

Constants

View Source
const SortDirectionAscending = "ASC"

SortDirectionAscending is the token that designates that records should be sorted lowest to highest

View Source
const SortDirectionDescending = "DESC"

SortDirectionDescending is the token that designates that records should be sorted highest to lowest

View Source
const TypeCaseSensitive = "CASESENSITIVE"

TypeCaseSensitive is the token that designates case sensitivity of search results

View Source
const TypeFields = "FIELDS"

TypeFields is the token that designates the fields to be returned

View Source
const TypeFirstRow = "FIRSTROW"

TypeFirstRow is the token that designates the "first row only" query option.

View Source
const TypeMaxRows = "MAXROWS"

TypeMaxRows is the token that designates the maximum number of records to be returned

View Source
const TypeSort = "SORT"

TypeSort is the token that designates a Sort order

Variables

This section is empty.

Functions

This section is empty.

Types

type CaseSensitiveOption added in v0.29.0

type CaseSensitiveOption bool

CaseSensitiveOption is a query option that designates case sensitivity of search results.

func (CaseSensitiveOption) CaseSensitive added in v0.29.0

func (option CaseSensitiveOption) CaseSensitive() bool

CaseSensitive returns TRUE if the results should consider letter case

func (CaseSensitiveOption) OptionType added in v0.29.0

func (option CaseSensitiveOption) OptionType() string

OptionType identifies this object as a query option

type FieldsOption added in v0.29.0

type FieldsOption []string

FieldsOption is a query option that limits which fields are included in a dataset

func (FieldsOption) Fields added in v0.29.0

func (option FieldsOption) Fields() []string

Fields returns the names of the fields to include in a dataset

func (FieldsOption) OptionType added in v0.29.0

func (option FieldsOption) OptionType() string

OptionType identifies this object as a query option

type FirstRowOption added in v0.29.0

type FirstRowOption struct{}

FirstRowOption is a query option that returns only the first matching row of a dataset.

func (FirstRowOption) OptionType added in v0.29.0

func (option FirstRowOption) OptionType() string

OptionType identifies this object as a query option

type MaxRowsOption added in v0.29.0

type MaxRowsOption int64

MaxRowsOption is a query option that limits the number of rows to be included in a dataset. A value of zero means "no limit", which makes the zero value safe to use.

func (MaxRowsOption) MaxRows added in v0.29.0

func (option MaxRowsOption) MaxRows() int64

MaxRows returns the maximum number of rows to include in a dataset, where zero means "no limit"

func (MaxRowsOption) OptionType added in v0.29.0

func (option MaxRowsOption) OptionType() string

OptionType identifies this object as a query option

type Option

type Option interface {
	OptionType() string // OptionType identifies the type of query option, and may be used for debugging purposes.
}

Option is an interface that wraps all of the query options that can be used to modify a database query.

func CaseSensitive added in v0.29.0

func CaseSensitive(caseSensitive bool) Option

CaseSensitive returns a query option that will designate the case sensitivity of search results

func Fields added in v0.22.0

func Fields(fields ...string) Option

Fields returns a query option that will limit the query results to a certain set of fields

func FirstRow

func FirstRow() Option

FirstRow returns a query option that limits the results to only the first matching row.

func MaxRows

func MaxRows(maxRows int64) Option

MaxRows returns a query option that will limit the query results to a certain number of rows

func SortAsc

func SortAsc(fieldName string) Option

SortAsc returns a query option that will sort the query results in ASCENDING order

func SortDesc

func SortDesc(fieldName string) Option

SortDesc returns a query option that will sort the query results in DESCENDING order

type SortOption added in v0.29.0

type SortOption struct {
	FieldName string // FieldName is the name of the field to sort on
	Direction string // Direction is the sort order, either SortDirectionAscending or SortDirectionDescending
}

SortOption identifies the field and direction to use when sorting a dataset

func (SortOption) IsAscending added in v0.33.0

func (option SortOption) IsAscending() bool

IsAscending returns TRUE if this option sorts from lowest to highest

func (SortOption) IsDescending added in v0.33.0

func (option SortOption) IsDescending() bool

IsDescending returns TRUE if this option sorts from highest to lowest. Any direction other than SortDirectionDescending sorts ASCENDING.

func (SortOption) OptionType added in v0.29.0

func (option SortOption) OptionType() string

OptionType identifies this object as a query option

Jump to

Keyboard shortcuts

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