query

package
v0.62.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package query implements a simple query language for filtering beads.

The query language supports:

  • Field comparisons: status=open, priority>1, updated>7d
  • Boolean operators: AND, OR, NOT
  • Parentheses for grouping: (status=open OR status=blocked) AND priority<2
  • Date-relative expressions: updated>7d, created<30d

Example queries:

  • status=open AND priority>1
  • (status=open OR status=blocked) AND updated>7d
  • NOT status=closed
  • type=bug AND priority=0

Index

Constants

This section is empty.

Variables

View Source
var KnownFields = map[string]bool{

	"id":          true,
	"title":       true,
	"description": true,
	"desc":        true,
	"status":      true,
	"priority":    true,
	"type":        true,
	"assignee":    true,
	"owner":       true,

	"created":    true,
	"updated":    true,
	"closed":     true,
	"created_at": true,
	"updated_at": true,
	"closed_at":  true,

	"label":  true,
	"labels": true,

	"pinned":    true,
	"ephemeral": true,
	"template":  true,

	"spec":             true,
	"spec_id":          true,
	"parent":           true,
	"mol_type":         true,
	"notes":            true,
	"has_metadata_key": true,
}

KnownFields lists fields that can be queried.

Functions

This section is empty.

Types

type AndNode

type AndNode struct {
	Left  Node
	Right Node
}

AndNode represents a logical AND operation.

func (*AndNode) String

func (n *AndNode) String() string

type ComparisonNode

type ComparisonNode struct {
	Field     string
	Op        ComparisonOp
	Value     string
	ValueType TokenType // TokenIdent, TokenString, TokenNumber, or TokenDuration
}

ComparisonNode represents a field comparison (e.g., status=open).

func (*ComparisonNode) String

func (n *ComparisonNode) String() string

type ComparisonOp

type ComparisonOp int

ComparisonOp represents a comparison operator.

const (
	OpEquals ComparisonOp = iota
	OpNotEquals
	OpLess
	OpLessEq
	OpGreater
	OpGreaterEq
)

func (ComparisonOp) String

func (op ComparisonOp) String() string

String returns the string representation of a ComparisonOp.

type Evaluator

type Evaluator struct {
	// contains filtered or unexported fields
}

Evaluator converts a query AST to an IssueFilter and/or predicate function.

func NewEvaluator

func NewEvaluator(now time.Time) *Evaluator

NewEvaluator creates a new Evaluator with the given reference time.

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(node Node) (*QueryResult, error)

Evaluate evaluates the query AST and returns a QueryResult.

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer tokenizes a query string.

func NewLexer

func NewLexer(input string) *Lexer

NewLexer creates a new Lexer for the given input string.

func (*Lexer) NextToken

func (l *Lexer) NextToken() (Token, error)

NextToken returns the next token from the input.

func (*Lexer) Tokenize

func (l *Lexer) Tokenize() ([]Token, error)

Tokenize returns all tokens from the input.

type Node

type Node interface {
	String() string
	// contains filtered or unexported methods
}

Node represents a node in the query AST.

func Parse

func Parse(input string) (Node, error)

Parse is a convenience function that parses a query string.

type NotNode

type NotNode struct {
	Operand Node
}

NotNode represents a logical NOT operation.

func (*NotNode) String

func (n *NotNode) String() string

type OrNode

type OrNode struct {
	Left  Node
	Right Node
}

OrNode represents a logical OR operation.

func (*OrNode) String

func (n *OrNode) String() string

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser parses a query string into an AST.

func NewParser

func NewParser(input string) *Parser

NewParser creates a new Parser for the given input.

func (*Parser) Parse

func (p *Parser) Parse() (Node, error)

Parse parses the query string and returns the root AST node.

type QueryResult

type QueryResult struct {
	// Filter contains filters that can be passed to SearchIssues.
	// This is always populated with at least base filters.
	Filter types.IssueFilter

	// Predicate is a function that evaluates whether an issue matches the query.
	// If nil, the Filter alone is sufficient.
	// If non-nil, issues matching Filter should be further filtered by Predicate.
	Predicate func(*types.Issue) bool

	// RequiresPredicate indicates if in-memory filtering is needed.
	// True when the query contains OR or complex NOT expressions.
	RequiresPredicate bool
}

QueryResult contains the result of evaluating a query. For simple queries, Filter will be populated and Predicate will be nil. For complex queries with OR, Predicate will be set and Filter will contain base filters that can pre-filter issues.

func Evaluate

func Evaluate(query string) (*QueryResult, error)

Evaluate is a convenience function that parses and evaluates a query string.

func EvaluateAt

func EvaluateAt(query string, now time.Time) (*QueryResult, error)

EvaluateAt parses and evaluates a query string with a specific reference time.

type Token

type Token struct {
	Type  TokenType
	Value string
	Pos   int // Position in input string
}

Token represents a single token from the lexer.

type TokenType

type TokenType int

TokenType represents the type of a lexer token.

const (
	TokenEOF       TokenType = iota
	TokenIdent               // field names, values
	TokenString              // quoted strings
	TokenNumber              // numeric values
	TokenDuration            // duration values like 7d, 24h
	TokenEquals              // =
	TokenNotEquals           // !=
	TokenLess                // <
	TokenLessEq              // <=
	TokenGreater             // >
	TokenGreaterEq           // >=
	TokenAnd                 // AND
	TokenOr                  // OR
	TokenNot                 // NOT
	TokenLParen              // (
	TokenRParen              // )
	TokenComma               // , (for lists)
)

func (TokenType) String

func (t TokenType) String() string

String returns the string representation of a TokenType.

Jump to

Keyboard shortcuts

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