query

package
v0.4.17 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpEq          = "="
	OpNeq         = "!="
	OpLt          = "<"
	OpGt          = ">"
	OpLte         = "<="
	OpGte         = ">="
	OpContains    = "~"
	OpNotContains = "!~"
	OpIn          = "IN"
	OpNotIn       = "NOT IN"
)

Operator constants

View Source
const (
	OpAnd = "AND"
	OpOr  = "OR"
	OpNot = "NOT"
)

Boolean operator constants

View Source
const (
	// DefaultMaxResults limits in-memory filtering to prevent OOM
	DefaultMaxResults = 10000
	// MaxDescendantDepth prevents infinite recursion in descendant_of
	MaxDescendantDepth = 100
)
View Source
const MaxQueryDepth = 50

MaxQueryDepth limits nesting to prevent stack overflow

Variables

View Source
var CrossEntityFields = map[string]map[string]string{
	"log": {
		"message":   "string",
		"type":      "enum",
		"timestamp": "date",
		"session":   "string",
	},
	"comment": {
		"text":    "string",
		"created": "date",
		"session": "string",
	},
	"handoff": {
		"done":      "string",
		"remaining": "string",
		"decisions": "string",
		"uncertain": "string",
		"timestamp": "date",
	},
	"file": {
		"path": "string",
		"role": "enum",
	},
	"dep": {
		"blocks":     "string",
		"depends_on": "string",
	},
}

Cross-entity field mappings

View Source
var EnumValues = map[string][]string{
	"status":    {"open", "in_progress", "blocked", "in_review", "closed"},
	"type":      {"bug", "feature", "task", "epic", "chore"},
	"priority":  {"P0", "P1", "P2", "P3", "P4"},
	"log.type":  {"progress", "blocker", "decision", "hypothesis", "tried", "result"},
	"file.role": {"implementation", "test", "reference", "config"},
}

Enum values for validation

View Source
var KnownFields = map[string]string{

	"id":          "string",
	"title":       "string",
	"description": "string",
	"status":      "enum",
	"type":        "enum",
	"priority":    "ordinal",
	"points":      "number",
	"labels":      "string",
	"parent":      "string",
	"epic":        "string",
	"implementer": "string",
	"reviewer":    "string",
	"minor":       "bool",
	"branch":      "string",
	"created":     "date",
	"updated":     "date",
	"closed":      "date",

	"log":     "prefix",
	"comment": "prefix",
	"handoff": "prefix",
	"file":    "prefix",
	"dep":     "prefix",
}

Known field names for validation

View Source
var KnownFunctions = map[string]struct {
	MinArgs int
	MaxArgs int
	Help    string
}{
	"has":           {1, 1, "has(field) - field is not empty"},
	"is":            {1, 1, "is(status) - shorthand for status check"},
	"any":           {2, -1, "any(field, v1, v2, ...) - field matches any value"},
	"all":           {2, -1, "all(field, v1, v2, ...) - field matches all values"},
	"none":          {2, -1, "none(field, v1, v2, ...) - field matches none"},
	"blocks":        {1, 1, "blocks(id) - issues that block the given id"},
	"blocked_by":    {1, 1, "blocked_by(id) - issues blocked by the given id"},
	"child_of":      {1, 1, "child_of(id) - direct children of issue"},
	"descendant_of": {1, 1, "descendant_of(id) - all descendants (recursive)"},
	"linked_to":     {1, 1, "linked_to(path) - issues linked to file path"},
}

Known functions

View Source
var SortFieldToColumn = map[string]string{
	"created":  "created_at",
	"updated":  "updated_at",
	"closed":   "closed_at",
	"deleted":  "deleted_at",
	"priority": "priority",
	"id":       "id",
	"title":    "title",
	"status":   "status",
	"points":   "points",
}

SortFieldToColumn maps user-facing sort field names to DB columns

Functions

func Execute

func Execute(database *db.DB, queryStr string, sessionID string, opts ExecuteOptions) ([]models.Issue, error)

Execute parses and executes a TDQ query

func QuickSearch

func QuickSearch(database *db.DB, text string, sessionID string, limit int) ([]models.Issue, error)

QuickSearch performs a simple text search (backward compatible with existing search)

Types

type BinaryExpr

type BinaryExpr struct {
	Op    string // "AND" or "OR"
	Left  Node
	Right Node
}

BinaryExpr represents a binary expression (AND, OR)

func (*BinaryExpr) String

func (b *BinaryExpr) String() string

type CommentEntry

type CommentEntry struct {
	Text    string
	Created time.Time
	Session string
}

CommentEntry represents a comment for cross-entity filtering

type DateValue

type DateValue struct {
	Raw      string // original value: "2024-01-15", "-7d", "today", etc.
	Relative bool   // true if relative date
}

DateValue represents a date (absolute or relative)

func (*DateValue) String

func (d *DateValue) String() string

type EvalContext

type EvalContext struct {
	CurrentSession string    // for @me resolution
	Now            time.Time // for relative date calculation
}

EvalContext provides context for query evaluation

func NewEvalContext

func NewEvalContext(sessionID string) *EvalContext

NewEvalContext creates a new evaluation context

type Evaluator

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

Evaluator converts a Query AST to SQL conditions and in-memory filters

func NewEvaluator

func NewEvaluator(ctx *EvalContext, query *Query) *Evaluator

NewEvaluator creates a new query evaluator

func (*Evaluator) HasCrossEntityConditions

func (e *Evaluator) HasCrossEntityConditions() bool

HasCrossEntityConditions checks if the query has cross-entity conditions

func (*Evaluator) ToMatcher

func (e *Evaluator) ToMatcher() (func(models.Issue) bool, error)

ToMatcher returns a function that matches issues in memory Used for complex conditions that can't be expressed in SQL

func (*Evaluator) ToSQLConditions

func (e *Evaluator) ToSQLConditions() ([]SQLCondition, error)

ToSQLConditions converts the query to SQL WHERE clauses Returns conditions that can be pushed to the database

type ExecuteOptions

type ExecuteOptions struct {
	Limit      int
	SortBy     string
	SortDesc   bool
	MaxResults int // Max issues to process in-memory (0 = DefaultMaxResults)
}

ExecuteOptions contains options for query execution

type FieldExpr

type FieldExpr struct {
	Field    string      // e.g., "status", "log.message"
	Operator string      // =, !=, ~, !~, <, >, <=, >=
	Value    interface{} // string, int, date value, or special value
}

FieldExpr represents a field comparison (field op value)

func (*FieldExpr) String

func (f *FieldExpr) String() string

type FileEntry

type FileEntry struct {
	Path string
	Role string
}

FileEntry represents a linked file for cross-entity filtering

type FunctionCall

type FunctionCall struct {
	Name string
	Args []interface{}
}

FunctionCall represents a function call like has(labels), is(open)

func (*FunctionCall) String

func (fn *FunctionCall) String() string

type HandoffEntry

type HandoffEntry struct {
	Done      string
	Remaining string
	Decisions string
	Uncertain string
	Timestamp time.Time
}

HandoffEntry represents a handoff for cross-entity filtering

type Lexer

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

Lexer tokenizes TDQ query strings

func NewLexer

func NewLexer(input string) *Lexer

NewLexer creates a new lexer for the given input

func (*Lexer) Tokenize

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

Tokenize returns all tokens from the input

type ListValue

type ListValue struct {
	Values []interface{}
}

ListValue represents a list of values for IN operator

func (*ListValue) String

func (l *ListValue) String() string

type LogEntry

type LogEntry struct {
	Message   string
	Type      string
	Timestamp time.Time
	Session   string
}

LogEntry represents a log entry for cross-entity filtering

type Node

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

Node is the interface for all AST nodes

type ParseError

type ParseError struct {
	Message  string
	Pos      int
	Line     int
	Column   int
	Token    Token
	Expected string
}

ParseError represents a parsing error with position information

func (*ParseError) Error

func (e *ParseError) Error() string

type Parser

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

Parser parses TDQ query strings into an AST

type Query

type Query struct {
	Root Node
	Raw  string      // original query string
	Sort *SortClause // optional sort clause
}

Query represents a parsed TDQ query

func Parse

func Parse(input string) (*Query, error)

Parse parses a TDQ query string and returns a Query AST

func (*Query) String

func (q *Query) String() string

func (*Query) Validate

func (q *Query) Validate() []error

Validate checks the query AST for semantic errors

type QueryResult

type QueryResult struct {
	Issues []models.Issue

	// For cross-entity queries, we may need to filter after fetching
	CrossEntityFilter func(issue models.Issue, logs []LogEntry, comments []CommentEntry, handoffs []HandoffEntry, files []FileEntry) bool
}

QueryResult contains the result of query evaluation

type SQLCondition

type SQLCondition struct {
	Clause string
	Args   []interface{}
}

SQLCondition represents a SQL WHERE clause fragment

type SortClause added in v0.4.15

type SortClause struct {
	Field      string // DB column name (e.g., "created_at", "priority")
	Descending bool   // true for descending order
}

SortClause represents a sort specification

func (*SortClause) String added in v0.4.15

func (s *SortClause) String() string

type SpecialValue

type SpecialValue struct {
	Type string // "me", "empty", "null"
}

SpecialValue represents special values like @me, EMPTY, NULL

func (*SpecialValue) String

func (s *SpecialValue) String() string

type TextSearch

type TextSearch struct {
	Text string
}

TextSearch represents a bare text search (searches title, description, id)

func (*TextSearch) String

func (t *TextSearch) String() string

type Token

type Token struct {
	Type   TokenType
	Value  string
	Pos    int // position in input
	Line   int
	Column int
}

Token represents a lexer token

func (Token) String

func (t Token) String() string

type TokenType

type TokenType int

TokenType represents the type of a lexer token

const (
	// Special tokens
	TokenEOF TokenType = iota
	TokenError

	// Literals
	TokenIdent  // field names, function names
	TokenString // "quoted" or 'quoted' strings
	TokenNumber // integers
	TokenDate   // 2024-01-15

	// Operators
	TokenEq          // =
	TokenNeq         // !=
	TokenLt          // <
	TokenGt          // >
	TokenLte         // <=
	TokenGte         // >=
	TokenContains    // ~
	TokenNotContains // !~

	// Boolean operators
	TokenAnd // AND, &&
	TokenOr  // OR, ||
	TokenNot // NOT, !, -

	// Delimiters
	TokenLParen // (
	TokenRParen // )
	TokenComma  // ,
	TokenDot    // .

	// Special values
	TokenAtMe  // @me
	TokenEmpty // EMPTY
	TokenNull  // NULL

	// Sort clause
	TokenSort // sort:field or sort:-field
)

func (TokenType) String

func (t TokenType) String() string

type UnaryExpr

type UnaryExpr struct {
	Op   string // "NOT"
	Expr Node
}

UnaryExpr represents a unary expression (NOT)

func (*UnaryExpr) String

func (u *UnaryExpr) String() string

Jump to

Keyboard shortcuts

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