Documentation
¶
Overview ¶
Package query implements the Raven query language parser and executor.
Index ¶
- type AncestorPredicate
- type ArrayQuantifierPredicate
- type ArrayQuantifierType
- type AtPredicate
- type ChildPredicate
- type CompareOp
- type ContainsPredicate
- type ContentPredicate
- type DescendantPredicate
- type ElementEqualityPredicate
- type Executor
- func (e *Executor) Execute(queryStr string) (interface{}, error)
- func (e *Executor) ExecuteObjectQuery(q *Query) ([]model.Object, error)
- func (e *Executor) ExecuteTraitQuery(q *Query) ([]model.Trait, error)
- func (e *Executor) SetDailyDirectory(dir string)
- func (e *Executor) SetResolver(r *resolver.Resolver)
- func (e *Executor) SetSchema(sch *schema.Schema)
- type FieldPredicate
- type GroupPredicate
- type HasPredicate
- type Lexer
- type NotPredicate
- type OnPredicate
- type OrPredicate
- type ParentPredicate
- type Parser
- type Predicate
- type Query
- type QueryType
- type RefdPredicate
- type RefsPredicate
- type StringFuncPredicate
- type StringFuncType
- type Token
- type TokenType
- type ValidationError
- type Validator
- type ValuePredicatedeprecated
- type WithinPredicate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AncestorPredicate ¶
type AncestorPredicate struct {
Target string // Specific target ID (mutually exclusive with SubQuery)
SubQuery *Query // An object query (mutually exclusive with Target)
// contains filtered or unexported fields
}
AncestorPredicate filters by any ancestor matching. Syntax: ancestor:{object:type ...}, ancestor:[[target]], ancestor:_
type ArrayQuantifierPredicate ¶
type ArrayQuantifierPredicate struct {
Quantifier ArrayQuantifierType
Field string // The array field to iterate
ElementPred Predicate // Predicate to test against each element (uses _ as element reference)
// contains filtered or unexported fields
}
ArrayQuantifierPredicate represents an array quantifier predicate. Syntax: any(.tags, _ == "urgent"), all(.tags, startswith(_, "feature-"))
type ArrayQuantifierType ¶
type ArrayQuantifierType int
ArrayQuantifierType represents the type of array quantifier.
const ( ArrayQuantifierAny ArrayQuantifierType = iota // any(.field, predicate) - any element matches ArrayQuantifierAll // all(.field, predicate) - all elements match ArrayQuantifierNone // none(.field, predicate) - no element matches )
func (ArrayQuantifierType) String ¶
func (aq ArrayQuantifierType) String() string
type AtPredicate ¶
type AtPredicate struct {
Target string // Specific trait ID (if referencing a known trait)
SubQuery *Query // A trait query to match against
// contains filtered or unexported fields
}
AtPredicate filters traits by co-location (same file:line). Syntax: at:{trait:name ...}, at:[[target]], at:_ For traits only - matches traits at the same file and line.
type ChildPredicate ¶
type ChildPredicate struct {
Target string // Specific target ID (mutually exclusive with SubQuery)
SubQuery *Query // An object query (mutually exclusive with Target)
// contains filtered or unexported fields
}
ChildPredicate filters by having a direct child matching. Syntax: child:{object:type ...}, child:[[target]], child:_
type ContainsPredicate ¶
type ContainsPredicate struct {
SubQuery *Query // A trait query
// contains filtered or unexported fields
}
ContainsPredicate filters objects by whether they contain matching traits anywhere in their subtree (self or any descendant object). Syntax: encloses(trait:name ...)
type ContentPredicate ¶
type ContentPredicate struct {
SearchTerm string // The search term or phrase
// contains filtered or unexported fields
}
ContentPredicate filters objects by full-text search on their content. Syntax: content("search terms"), content("exact phrase")
type DescendantPredicate ¶
type DescendantPredicate struct {
Target string // Specific target ID (mutually exclusive with SubQuery)
SubQuery *Query // An object query (mutually exclusive with Target)
// contains filtered or unexported fields
}
DescendantPredicate filters by having any descendant matching (at any depth). Syntax: descendant:{object:type ...}, descendant:[[target]], descendant:_
type ElementEqualityPredicate ¶
type ElementEqualityPredicate struct {
Value string
CompareOp CompareOp // == or !=
IsRefValue bool // true if the value came from a [[ref]] token
// contains filtered or unexported fields
}
ElementEqualityPredicate represents _ == value or _ != value within array context. Syntax: _ == "urgent", _ != "deprecated"
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor executes queries against the database.
func (*Executor) Execute ¶
Execute parses and executes a query string, returning either object or trait results.
func (*Executor) ExecuteObjectQuery ¶
ExecuteObjectQuery executes an object query and returns matching objects.
func (*Executor) ExecuteTraitQuery ¶
ExecuteTraitQuery executes a trait query and returns matching traits.
func (*Executor) SetDailyDirectory ¶
SetDailyDirectory sets the daily directory used when building a fallback resolver.
This matters for date shorthand references like [[2026-01-01]], which resolve to <dailyDirectory>/2026-01-01.
func (*Executor) SetResolver ¶
SetResolver injects a resolver for target resolution.
This allows callers (CLI/MCP) to provide a canonical resolver that includes aliases and vault-specific settings like daily directory. If not set, the executor will fall back to building a resolver from the objects table.
type FieldPredicate ¶
type FieldPredicate struct {
Field string
Value string // "*" means "exists"
IsExists bool // true if Value is "*"
CompareOp CompareOp // comparison operator (==, !=, <, >, <=, >=)
IsRefValue bool // true if the value came from a [[ref]] token
// contains filtered or unexported fields
}
FieldPredicate filters by object field value. Syntax: .field==value, .field>value, exists(.field) For string matching, use StringFuncPredicate (contains, startswith, endswith, matches).
type GroupPredicate ¶
type GroupPredicate struct {
Predicates []Predicate
// contains filtered or unexported fields
}
GroupPredicate represents a parenthesized group of predicates. Used for explicit precedence control.
type HasPredicate ¶
type HasPredicate struct {
SubQuery *Query // A trait query
// contains filtered or unexported fields
}
HasPredicate filters objects by whether they contain matching traits. Syntax: has(trait:name .value==...)
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer tokenizes a query string.
type NotPredicate ¶
type NotPredicate struct {
Inner Predicate
}
NotPredicate represents the negation of a predicate. Syntax: !(pred), !pred
func (NotPredicate) Negated ¶
func (NotPredicate) Negated() bool
type OnPredicate ¶
type OnPredicate struct {
Target string // Specific target ID (mutually exclusive with SubQuery)
SubQuery *Query // An object query (mutually exclusive with Target)
// contains filtered or unexported fields
}
OnPredicate filters traits by direct parent object. Syntax: on(object:type ...), on([[target]]), on(_)
type OrPredicate ¶
type OrPredicate struct {
Predicates []Predicate
// contains filtered or unexported fields
}
OrPredicate represents an OR combination of two or more predicates. Syntax: (pred1 | pred2 | pred3)
type ParentPredicate ¶
type ParentPredicate struct {
Target string // Specific target ID (mutually exclusive with SubQuery)
SubQuery *Query // An object query (mutually exclusive with Target)
// contains filtered or unexported fields
}
ParentPredicate filters by direct parent matching. Syntax: parent:{object:type ...}, parent:[[target]], parent:_
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses query strings into Query ASTs.
type Predicate ¶
type Predicate interface {
Negated() bool
// contains filtered or unexported methods
}
Predicate represents a filter condition in a query.
type Query ¶
type Query struct {
Type QueryType
TypeName string // Object type or trait name
Predicate Predicate // Filter to apply (may be nil)
}
Query represents a parsed query.
type RefdPredicate ¶
type RefdPredicate struct {
Target string // Specific source ID
SubQuery *Query // Query matching the sources that reference this
// contains filtered or unexported fields
}
RefdPredicate filters objects/traits by what references them (inverse of refs:). Syntax: refd(object:type ...), refd(trait:name ...), refd([[target]]), refd(target)
type RefsPredicate ¶
type RefsPredicate struct {
Target string // Specific target like "projects/website" (mutually exclusive with SubQuery)
SubQuery *Query // Subquery to match targets (mutually exclusive with Target)
// contains filtered or unexported fields
}
RefsPredicate filters objects by what they reference. Syntax: refs([[target]]), refs(target), refs(object:type ...)
type StringFuncPredicate ¶
type StringFuncPredicate struct {
FuncType StringFuncType
Field string // Field name (without .) or "_" for array element
Value string // The string to match against
CaseSensitive bool // If true, match is case-sensitive (default: false)
IsElementRef bool // True if Field is "_" (array element reference)
// contains filtered or unexported fields
}
StringFuncPredicate represents a string function predicate. Syntax: contains(.field, "value"), startswith(.field, "value"), etc. Can also be used with _ as the field for array element context.
type StringFuncType ¶
type StringFuncType int
StringFuncType represents the type of string function.
const ( StringFuncIncludes StringFuncType = iota // contains(.field, "str") - substring match StringFuncStartsWith // startswith(.field, "str") StringFuncEndsWith // endswith(.field, "str") StringFuncMatches // matches(.field, "pattern") - regex match )
func (StringFuncType) String ¶
func (sf StringFuncType) String() string
type Token ¶
type Token struct {
Type TokenType
Value string
Pos int
Literal string // original text for references
}
Token represents a lexer token.
type TokenType ¶
type TokenType int
TokenType represents the type of a lexer token.
const ( TokenEOF TokenType = iota TokenIdent // identifiers like "object", "trait", "project", "due" TokenColon // : TokenDot // . TokenBang // ! TokenPipe // | TokenPipeline // |> TokenLParen // ( TokenRParen // ) TokenLBrace // { TokenRBrace // } TokenLBracket // [ TokenRBracket // ] TokenStar // * TokenRef // [[...]] reference TokenString // "quoted string" for content search TokenRegex // /pattern/ for regex matching TokenUnderscore // _ (result reference) TokenLt // < TokenGt // > TokenLte // <= TokenGte // >= TokenEq // = TokenEqEq // == TokenBangEq // != TokenComma // , TokenError // error token )
type ValidationError ¶
ValidationError represents a query validation error.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator validates queries against a schema.
func NewValidator ¶
NewValidator creates a new query validator.
type ValuePredicate
deprecated
type ValuePredicate struct {
Value string
CompareOp CompareOp // comparison operator (==, !=, <, >, <=, >=)
// contains filtered or unexported fields
}
ValuePredicate filters traits by value.
Deprecated: Use FieldPredicate with Field="value" instead. The parser now creates FieldPredicate for .value== syntax. This type is retained for internal SQL generation helpers.
type WithinPredicate ¶
type WithinPredicate struct {
Target string // Specific target ID (mutually exclusive with SubQuery)
SubQuery *Query // An object query (mutually exclusive with Target)
// contains filtered or unexported fields
}
WithinPredicate filters traits by any ancestor object. Syntax: within(object:type ...), within([[target]]), within(_)
Source Files
¶
- ast.go
- compare_helpers.go
- executor.go
- executor_resolver.go
- executor_run.go
- executor_types.go
- lexer.go
- parser.go
- parser_core.go
- predicate_sql_helpers.go
- regexp.go
- sql_build_query.go
- sql_exec.go
- sql_like_helpers.go
- sql_predicate_dispatch.go
- sql_predicates_object_fields.go
- sql_predicates_object_nav.go
- sql_predicates_shared.go
- sql_predicates_trait.go
- validator.go