Documentation
¶
Index ¶
- Constants
- Variables
- func Execute(database *db.DB, queryStr string, sessionID string, opts ExecuteOptions) ([]models.Issue, error)
- func QuickSearch(database *db.DB, text string, sessionID string, limit int) ([]models.Issue, error)
- type BinaryExpr
- type CommentEntry
- type DateValue
- type EvalContext
- type Evaluator
- type ExecuteOptions
- type FieldExpr
- type FileEntry
- type FunctionCall
- type HandoffEntry
- type Lexer
- type ListValue
- type LogEntry
- type Node
- type ParseError
- type Parser
- type Query
- type QueryResult
- type SQLCondition
- type SortClause
- type SpecialValue
- type TextSearch
- type Token
- type TokenType
- type UnaryExpr
Constants ¶
const ( OpEq = "=" OpNeq = "!=" OpLt = "<" OpGt = ">" OpLte = "<=" OpGte = ">=" OpContains = "~" OpNotContains = "!~" OpIn = "IN" OpNotIn = "NOT IN" )
Operator constants
const ( OpAnd = "AND" OpOr = "OR" OpNot = "NOT" )
Boolean operator constants
const ( // DefaultMaxResults limits in-memory filtering to prevent OOM DefaultMaxResults = 10000 // MaxDescendantDepth prevents infinite recursion in descendant_of MaxDescendantDepth = 100 )
const MaxQueryDepth = 50
MaxQueryDepth limits nesting to prevent stack overflow
Variables ¶
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
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
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",
"sprint": "string",
"created": "date",
"updated": "date",
"closed": "date",
"log": "prefix",
"comment": "prefix",
"handoff": "prefix",
"file": "prefix",
"dep": "prefix",
}
Known field names for validation
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"}, "rework": {0, 0, "rework() - issues rejected and awaiting rework"}, "label": {1, 1, "label(name) - issues with the given label"}, "labels": {1, 1, "labels(name) - alias for label()"}, }
Known functions
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",
"sprint": "sprint",
}
SortFieldToColumn maps user-facing sort field names to DB columns
Functions ¶
Types ¶
type BinaryExpr ¶
BinaryExpr represents a binary expression (AND, OR)
func (*BinaryExpr) String ¶
func (b *BinaryExpr) String() string
type CommentEntry ¶
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)
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 ¶
HasCrossEntityConditions checks if the query has cross-entity conditions
func (*Evaluator) ToMatcher ¶
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)
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
type ListValue ¶
type ListValue struct {
Values []interface{}
}
ListValue represents a list of values for IN operator
type Node ¶
type Node interface {
String() string
// contains filtered or unexported methods
}
Node is the interface for all AST nodes
type ParseError ¶
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
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 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 )