Help us shape the future of Go! Take the 2026 Go Developer Survey

queryfield

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field[T any] struct {
	Column string
	Kind   Kind
	// contains filtered or unexported fields
}

Field is the column a query field name resolves to. Column is repo-controlled SQL, never client input.

func Bool

func Bool[T any, V boolValue](column string, value func(T) V) Field[T]

Bool reads a filter value as the word, so a filter writes hidden = true with no quotes around it.

func Duration added in v0.3.0

func Duration[T any, V durationValue](column string, unit time.Duration, value func(T) V) Field[T]

Duration declares a column counting whole multiples of unit, such as time.Second for a column of seconds. A filter writes the seconds form of google.protobuf.Duration, such as "7200s" or "1.5s", and the field binds the count of units. A value finer than the unit is rejected.

func Enum

func Enum[T any, V textValue](
	column string,
	values map[string]string,
	value func(T) V,
) Field[T]

Enum maps the name a filter writes to the word the column holds, so a filter writes phase = PHASE_OPEN against a column holding open. A name outside the map is rejected, which keeps the stored words out of the API.

func Float

func Float[T any, V floatValue](column string, value func(T) V) Field[T]

Float encodes the cursor as the shortest decimal that parses back to the same bits, so a page boundary never skips or repeats a row.

func Int

func Int[T any, V intValue](column string, value func(T) V) Field[T]

func ResourceName

func ResourceName[T any, V textValue](
	column string,
	pattern resourcename.Pattern,
	value func(T) V,
) Field[T]

ResourceName declares a column holding the id a resource name ends in, so a filter writes books/abc against a column holding abc. Its kind separates it from text, since a fragment of a name reaches no pattern and unpacks to no id.

func Text

func Text[T any, V textValue](column string, value func(T) V) Field[T]

func Time

func Time[T any, V timeValue](column string, value func(T) V) Field[T]

Time encodes the cursor as epoch microseconds, the resolution timestamptz stores, and reads a filter value as the RFC3339 AIP-160 states.

func (Field[T]) Cursor

func (f Field[T]) Cursor(row T) *string

Cursor returns the column encoded for a page token, or nil where it is NULL.

func (Field[T]) Declared

func (f Field[T]) Declared() bool

Declared reports whether the field came from a constructor.

func (Field[T]) Nullable

func (f Field[T]) Nullable() bool

func (Field[T]) ParseCursor

func (f Field[T]) ParseCursor(raw string) (any, error)

func (Field[T]) ParseLiteral

func (f Field[T]) ParseLiteral(raw string) (any, error)

ParseLiteral returns the bind argument a filter value stands for, which a cursor value of the same column does not always spell the same way.

func (Field[T]) Zero

func (f Field[T]) Zero() string

Zero returns the SQL literal COALESCE puts in place of NULL, which collapses the NULL rows onto one value a row comparison still decides against.

type Kind

type Kind int
const (
	KindText Kind = iota
	KindTime
	KindInt
	KindResourceName
	KindBool
	KindFloat
	KindEnum
	KindDuration
)

Jump to

Keyboard shortcuts

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