ast
April 23, 2026 · View on GitHub
import "github.com/CaliLuke/go-typeql/ast"
Package ast provides builder helpers for ergonomic AST construction.
Package ast defines the Abstract Syntax Tree (AST) for TypeQL queries.
Package ast defines the Abstract Syntax Tree (AST) for TypeQL queries.
It decouples query construction from string formatting, providing a structured way to build TypeQL queries programmatically.
Index
- func DeleteArtifact(identifier, typeName string) (string, error)
- func DeleteArtifactWithOptions(identifier, typeName string, opts DeleteArtifactOptions) (string, error)
- func EscapeString(s string) string
- func FormatGoValue(value any) string
- func FormatLiteral(val any, valueType string) string
- func PaginatedSearch(types []string, opts PaginatedSearchOptions) (string, error)
- func UpdateAttribute(varName, typeName, attrName string, value any) (string, error)
- type AggregateExpr
- type ArithmeticValue
- type AttributePattern
- type Clause
- type Compiler
- type Constraint
- type DeleteArtifactOptions
- type DeleteClause
- type DeleteHasStatement
- type DeleteThingStatement
- type EntityPattern
- type FetchAttribute
- type FetchAttributeList
- type FetchClause
- type FetchFunction
- type FetchItem
- type FetchNestedWildcard
- type FetchVariable
- type FetchWildcard
- type FunctionBuilder
- type FunctionCallValue
- type FunctionOutputBuilder
- func (b FunctionOutputBuilder) Build() (string, error)
- func (b FunctionOutputBuilder) BuildNodes() []QueryNode
- func (b FunctionOutputBuilder) Limit(count int) FunctionResultStage
- func (b FunctionOutputBuilder) Nodes() []QueryNode
- func (b FunctionOutputBuilder) Offset(count int) FunctionResultStage
- func (b FunctionOutputBuilder) Select(vars ...string) FunctionResultStage
- func (b FunctionOutputBuilder) Sort(variable, direction string) FunctionResultStage
- type FunctionResultStage
- type FunctionStage
- type HasConstraint
- type HasPattern
- type HasStatement
- type IdentifierMatcher
- type IidConstraint
- type IidPattern
- type InsertClause
- type IsaConstraint
- type IsaStatement
- type LetAssignment
- type LimitClause
- type LiteralValue
- type MatchBuilder
- func (b MatchBuilder) Build() (string, error)
- func (b MatchBuilder) BuildNodes() []QueryNode
- func (b MatchBuilder) DeleteHas(attrVar, ownerVar string) MatchStage
- func (b MatchBuilder) DeleteThing() MatchStage
- func (b MatchBuilder) Fetch(varName string, attrNames ...string) MatchResultStage
- func (b MatchBuilder) Has(attrName string, value any) MatchStage
- func (b MatchBuilder) Iid(iid string) MatchStage
- func (b MatchBuilder) InsertHas(ownerVar, attrName string, value any) MatchStage
- func (b MatchBuilder) Let(assignments ...LetAssignment) MatchStage
- func (b MatchBuilder) MatchByIdentifier(identifier, attrName string, matcher IdentifierMatcher) MatchStage
- func (b MatchBuilder) Nodes() []QueryNode
- func (b MatchBuilder) Or(alternatives ...[]Pattern) MatchStage
- func (b MatchBuilder) Select(vars ...string) MatchResultStage
- func (b MatchBuilder) Set(attrName string, value any) MatchStage
- func (b MatchBuilder) Where(patterns ...Pattern) MatchStage
- type MatchClause
- type MatchLetClause
- type MatchOutputBuilder
- func (b MatchOutputBuilder) Build() (string, error)
- func (b MatchOutputBuilder) BuildNodes() []QueryNode
- func (b MatchOutputBuilder) Fetch(varName string, attrNames ...string) MatchResultStage
- func (b MatchOutputBuilder) Limit(count int) MatchResultStage
- func (b MatchOutputBuilder) Nodes() []QueryNode
- func (b MatchOutputBuilder) Offset(count int) MatchResultStage
- func (b MatchOutputBuilder) Select(vars ...string) MatchResultStage
- func (b MatchOutputBuilder) Sort(variable, direction string) MatchResultStage
- type MatchResultStage
- type MatchStage
- type NotPattern
- type OffsetClause
- type OrPattern
- type PaginatedSearchOptions
- type Pattern
- type PrefixIdentifierMatcher
- type PutClause
- type QueryNode
- type RawPattern
- type RawStatement
- type ReduceAssignment
- type ReduceClause
- type RelationPattern
- type RelationStatement
- type RolePlayer
- type SelectClause
- type SortClause
- type Statement
- type SubTypePattern
- type UpdateClause
- type Value
- type ValueComparisonPattern
func DeleteArtifact
func DeleteArtifact(identifier, typeName string) (string, error)
DeleteArtifact builds a delete query that matches by IID or fallback attribute.
func DeleteArtifactWithOptions
func DeleteArtifactWithOptions(identifier, typeName string, opts DeleteArtifactOptions) (string, error)
DeleteArtifactWithOptions builds a delete query with custom identifier matching options.
func EscapeString
func EscapeString(s string) string
EscapeString escapes special characters in a string for use in TypeQL string literals. It handles backslashes, quotes, newlines, carriage returns, and tabs.
func FormatGoValue
func FormatGoValue(value any) string
FormatGoValue converts a Go value into its TypeQL literal string representation. It uses reflection to determine the type and handles basic types, pointers, and time.Time. This is the canonical formatting function for Go values; other packages should use this instead of implementing their own formatting logic.
func FormatLiteral
func FormatLiteral(val any, valueType string) string
FormatLiteral formats a Go value as a TypeQL literal string.
func PaginatedSearch
func PaginatedSearch(types []string, opts PaginatedSearchOptions) (string, error)
PaginatedSearch builds a standard typed search with sorting and pagination/fetch options.
func UpdateAttribute
func UpdateAttribute(varName, typeName, attrName string, value any) (string, error)
UpdateAttribute builds the standard Match-Delete-Insert sequence for one attribute update.
type AggregateExpr
AggregateExpr represents an aggregate expression like count(var\) or sum\(attr).
type AggregateExpr struct {
// FuncName is the name of the aggregate function (count, sum, min, max, mean, std, median).
FuncName string
// Var is the variable being aggregated.
Var string
// AttrName is the optional attribute name to aggregate on if the variable is a thing.
AttrName string
}
type ArithmeticValue
ArithmeticValue represents a binary arithmetic operation between two values. It supports TypeQL infix operators like +, -, *, /, %, and ^.
type ArithmeticValue struct {
// Left is the left operand (Value or variable string).
Left any
// Operator is the infix operator (+, -, *, /, %, ^).
Operator string
// Right is the right operand (Value or variable string).
Right any
}
type AttributePattern
AttributePattern matches an attribute of a specific type and optionally its value.
type AttributePattern struct {
// Variable is the variable name for the attribute.
Variable string
// TypeName is the name of the attribute type.
TypeName string
// Value is the optional value of the attribute.
Value Value
}
type Clause
Clause is the marker interface for top-level TypeQL clauses.
type Clause interface {
QueryNode
// contains filtered or unexported methods
}
type Compiler
Compiler compiles AST nodes into TypeQL query strings. It traverses the AST and generates the corresponding TypeQL syntax.
type Compiler struct{}
func (*Compiler) Compile
func (c *Compiler) Compile(node QueryNode) (string, error)
Compile compiles a single AST node into its TypeQL string representation. It returns an error if the node type is unknown or if compilation fails.
func (*Compiler) CompileBatch
func (c *Compiler) CompileBatch(nodes []QueryNode, separator string) (string, error)
CompileBatch compiles a list of AST nodes into a single query string. The separator controls how compiled nodes are joined; empty means newline.
type Constraint
Constraint is the marker interface for constraints applied to variables in a pattern.
type Constraint interface {
QueryNode
// contains filtered or unexported methods
}
type DeleteArtifactOptions
DeleteArtifactOptions configures DeleteArtifact matching behavior.
type DeleteArtifactOptions struct {
VarName string
IDAttr string
Matcher IdentifierMatcher
}
type DeleteClause
DeleteClause represents a 'delete' clause containing one or more statements.
type DeleteClause struct {
// Statements are the statements defining what to delete.
Statements []Statement
}
func Delete
func Delete(statements ...Statement) DeleteClause
Delete creates a DeleteClause with the given statements.
type DeleteHasStatement
DeleteHasStatement represents a statement to delete an attribute from its owner. Compiles to: ownerVar
type DeleteHasStatement struct {
// AttrVar is the variable representing the attribute to delete (e.g., "$old").
AttrVar string
// OwnerVar is the variable representing the owner entity/relation (e.g., "$e").
OwnerVar string
}
func DeleteHas
func DeleteHas(attrVar, ownerVar string) DeleteHasStatement
DeleteHas creates a DeleteHasStatement for deleting an attribute from its owner. Compiles to: ownerVar
type DeleteThingStatement
DeleteThingStatement represents a statement to delete a thing instance identified by a variable.
type DeleteThingStatement struct {
// Variable is the variable representing the thing to delete.
Variable string
}
type EntityPattern
EntityPattern matches an entity with an optional type and constraints.
type EntityPattern struct {
// Variable is the variable name for the matched entity.
Variable string
// TypeName is the name of the entity type.
TypeName string
// Constraints are additional constraints applied to the entity.
Constraints []Constraint
// IsStrict indicates whether to use strict type checking (isa!).
IsStrict bool
}
func Entity
func Entity(varName, typeName string, constraints ...Constraint) EntityPattern
Entity creates an EntityPattern with the given variable, type, and constraints.
type FetchAttribute
FetchAttribute fetches a single attribute value of a variable.
type FetchAttribute struct {
// Key is the output key in the result JSON.
Key string
// Var is the variable whose attribute is being fetched.
Var string
// AttrName is the name of the attribute type to fetch.
AttrName string
}
func FetchAttr
func FetchAttr(key, varName, attrName string) FetchAttribute
FetchAttr creates a FetchAttribute for fetching an attribute value. The attrPath should be like "$var.attrname".
func FetchAttrPath
func FetchAttrPath(key, attrPath string) FetchAttribute
FetchAttrPath is a convenience for creating FetchAttribute from a dotted path like "$p.name".
func (FetchAttribute) FetchKey
func (f FetchAttribute) FetchKey() string
FetchKey returns the output key for the attribute.
type FetchAttributeList
FetchAttributeList fetches all values of a multi-value attribute as a list.
type FetchAttributeList struct {
// Key is the output key in the result JSON.
Key string
// Var is the variable whose attributes are being fetched.
Var string
// AttrName is the name of the attribute type.
AttrName string
}
func (FetchAttributeList) FetchKey
func (f FetchAttributeList) FetchKey() string
FetchKey returns the output key for the attribute list.
type FetchClause
FetchClause defines the output structure of a query.
type FetchClause struct {
// Items are the items to fetch, which can be FetchItem nodes or raw strings.
Items []any
}
func Fetch
func Fetch(items ...FetchItem) FetchClause
Fetch creates a FetchClause with the given items.
type FetchFunction
FetchFunction fetches the result of a function applied to a variable.
type FetchFunction struct {
// Key is the output key in the result JSON.
Key string
// FuncName is the name of the function (e.g., "iid").
FuncName string
// Var is the variable the function is applied to.
Var string
}
func FetchFunc
func FetchFunc(key, funcName, varName string) FetchFunction
FetchFunc creates a FetchFunction for fetching the result of a function.
func (FetchFunction) FetchKey
func (f FetchFunction) FetchKey() string
FetchKey returns the output key for the function result.
type FetchItem
FetchItem is the marker interface for items in a 'fetch' clause.
type FetchItem interface {
QueryNode
// FetchKey returns the key under which the item will be returned in the result JSON.
FetchKey() string
// contains filtered or unexported methods
}
type FetchNestedWildcard
FetchNestedWildcard retrieves all attributes and their values recursively in a nested structure.
type FetchNestedWildcard struct {
// Key is the output key in the result JSON.
Key string
// Var is the variable being fetched.
Var string
}
func (FetchNestedWildcard) FetchKey
func (f FetchNestedWildcard) FetchKey() string
FetchKey returns the output key for the nested wildcard.
type FetchVariable
FetchVariable fetches a variable directly.
type FetchVariable struct {
// Key is the output key in the result JSON.
Key string
// Var is the variable being fetched.
Var string
}
func FetchVar
func FetchVar(key, varName string) FetchVariable
FetchVar creates a FetchVariable for fetching a variable directly.
func (FetchVariable) FetchKey
func (f FetchVariable) FetchKey() string
FetchKey returns the output key for the variable.
type FetchWildcard
FetchWildcard fetches all attributes of a variable.
type FetchWildcard struct {
// Key is the output key in the result JSON.
Key string
// Var is the variable whose attributes are all fetched.
Var string
}
func (FetchWildcard) FetchKey
func (f FetchWildcard) FetchKey() string
FetchKey returns the output key for the wildcard.
type FunctionBuilder
FunctionBuilder is the concrete immutable pre-output builder for function queries.
type FunctionBuilder struct {
// contains filtered or unexported fields
}
func (FunctionBuilder) Select
func (b FunctionBuilder) Select(vars ...string) FunctionResultStage
Select transitions function query to output stage.
type FunctionCallValue
FunctionCallValue represents a function call in TypeQL, such as iid($x).
type FunctionCallValue struct {
// Function is the name of the function to call.
Function string
// Args contains the arguments for the function, which can be Value nodes or variable strings.
Args []any
}
func FuncCall
func FuncCall(funcName string, args ...any) FunctionCallValue
FuncCall creates a FunctionCallValue with the given function name and arguments.
type FunctionOutputBuilder
FunctionOutputBuilder is the concrete immutable output-stage builder for function queries.
type FunctionOutputBuilder struct {
// contains filtered or unexported fields
}
func (FunctionOutputBuilder) Build
func (b FunctionOutputBuilder) Build() (string, error)
Build compiles the fluent query into TypeQL.
func (FunctionOutputBuilder) BuildNodes
func (b FunctionOutputBuilder) BuildNodes() []QueryNode
BuildNodes returns the compiled AST node sequence before string compilation.
func (FunctionOutputBuilder) Limit
func (b FunctionOutputBuilder) Limit(count int) FunctionResultStage
Limit configures a limit clause.
func (FunctionOutputBuilder) Nodes
func (b FunctionOutputBuilder) Nodes() []QueryNode
Nodes returns the compiled AST node sequence before string compilation.
func (FunctionOutputBuilder) Offset
func (b FunctionOutputBuilder) Offset(count int) FunctionResultStage
Offset configures an offset clause.
func (FunctionOutputBuilder) Select
func (b FunctionOutputBuilder) Select(vars ...string) FunctionResultStage
Select adds additional selected variables in output stage.
func (FunctionOutputBuilder) Sort
func (b FunctionOutputBuilder) Sort(variable, direction string) FunctionResultStage
Sort configures a sort clause.
type FunctionResultStage
FunctionResultStage is the output stage for function queries.
type FunctionResultStage interface {
Select(vars ...string) FunctionResultStage
Sort(variable, direction string) FunctionResultStage
Limit(count int) FunctionResultStage
Offset(count int) FunctionResultStage
Build() (string, error)
Nodes() []QueryNode
BuildNodes() []QueryNode
}
type FunctionStage
FunctionStage is the pre-output stage for function-based match-let queries.
type FunctionStage interface {
Select(vars ...string) FunctionResultStage
}
func MatchFunction
func MatchFunction(funcName string, args ...any) FunctionStage
MatchFunction starts a fluent function query compiled as match-let.
type HasConstraint
HasConstraint checks if a thing has a specific attribute with a given value.
type HasConstraint struct {
// AttrName is the name of the attribute type.
AttrName string
// Value is the value of the attribute (Value or variable string).
Value any
}
func Has
func Has(attrName string, value any) HasConstraint
Has creates a HasConstraint for the given attribute name and value. The value can be any Go value that will be formatted via FormatGoValue.
type HasPattern
HasPattern represents a pattern where a thing has an attribute assignment (v).
type HasPattern struct {
// ThingVar is the variable representing the thing (entity or relation).
ThingVar string
// AttrType is the type of the attribute.
AttrType string
// AttrVar is the variable representing the attribute instance.
AttrVar string
}
type HasStatement
HasStatement assigns an attribute value to a subject variable.
type HasStatement struct {
// SubjectVar is the variable representing the thing being assigned an attribute.
SubjectVar string
// AttrName is the name of the attribute type.
AttrName string
// Value is the value being assigned.
Value Value
}
func HasStmt
func HasStmt(subjectVar, attrName string, value Value) HasStatement
HasStmt creates a HasStatement for the given subject variable, attribute name, and value. The value must be a Value type (use Str(), Long(), etc. to create literal values).
type IdentifierMatcher
IdentifierMatcher determines whether an identifier should be treated as an IID.
type IdentifierMatcher interface {
IsIID(identifier string) bool
}
DefaultIdentifierMatcher treats values prefixed with "0x" as TypeDB IIDs.
var DefaultIdentifierMatcher IdentifierMatcher = PrefixIdentifierMatcher{Prefix: "0x"}
type IidConstraint
IidConstraint matches a thing by its internal instance ID (IID).
type IidConstraint struct {
// IID is the unique instance identifier.
IID string
}
func Iid
func Iid(iid string) IidConstraint
Iid creates an IidConstraint for the given IID value.
type IidPattern
IidPattern represents a pattern matching a thing by its IID ($x iid 0x...).
type IidPattern struct {
// Variable is the variable representing the thing.
Variable string
// IID is the instance ID string.
IID string
}
type InsertClause
InsertClause represents an 'insert' clause containing one or more statements.
type InsertClause struct {
// Statements are the statements to insert.
Statements []Statement
}
func Insert
func Insert(statements ...Statement) InsertClause
Insert creates an InsertClause with the given statements.
type IsaConstraint
IsaConstraint checks if a thing is an instance of a specific type.
type IsaConstraint struct {
// TypeName is the name of the type.
TypeName string
// Strict indicates whether to use strict type checking (isa!).
Strict bool
}
func Isa
func Isa(typeName string) IsaConstraint
Isa creates an IsaConstraint for the given type name.
func IsaExact
func IsaExact(typeName string) IsaConstraint
IsaExact creates a strict IsaConstraint (isa!) for the given type name.
type IsaStatement
IsaStatement defines the type of a variable in an insert statement.
type IsaStatement struct {
// Variable is the variable name.
Variable string
// TypeName is the name of the type.
TypeName string
}
func IsaStmt
func IsaStmt(variable, typeName string) IsaStatement
IsaStmt creates an IsaStatement for the given variable and type name.
type LetAssignment
LetAssignment represents an assignment in a 'match let' clause.
type LetAssignment struct {
// Variables are the variables being assigned values.
Variables []string
// Expression is the value or expression being assigned (Value or variable string).
Expression any
// IsStream indicates whether to use stream assignment ('in') or scalar assignment ('=').
IsStream bool
}
type LimitClause
LimitClause represents a 'limit' clause for restricting result count.
type LimitClause struct {
// Count is the maximum number of results to return.
Count int
}
func Limit
func Limit(count int) LimitClause
Limit creates a LimitClause with the given count.
type LiteralValue
LiteralValue represents a literal value such as a string, number, or boolean.
type LiteralValue struct {
// Val is the actual value.
Val any
// ValueType specifies the TypeQL type of the value (e.g., "string", "long", "boolean").
ValueType string
}
func Bool
func Bool(b bool) LiteralValue
Bool creates a boolean LiteralValue.
func Double
func Double(f float64) LiteralValue
Double creates a double LiteralValue.
func Lit
func Lit(value any, valueType string) LiteralValue
Lit creates a LiteralValue with the given value and type.
func Long
func Long(n int64) LiteralValue
Long creates an integer LiteralValue.
func Str
func Str(s string) LiteralValue
Str creates a string LiteralValue.
type MatchBuilder
MatchBuilder is the concrete immutable builder for entity-first match queries.
type MatchBuilder struct {
// contains filtered or unexported fields
}
func (MatchBuilder) Build
func (b MatchBuilder) Build() (string, error)
Build compiles the fluent query into TypeQL.
func (MatchBuilder) BuildNodes
func (b MatchBuilder) BuildNodes() []QueryNode
BuildNodes returns the compiled AST node sequence before string compilation.
func (MatchBuilder) DeleteHas
func (b MatchBuilder) DeleteHas(attrVar, ownerVar string) MatchStage
DeleteHas emits an explicit delete-has statement.
func (MatchBuilder) DeleteThing
func (b MatchBuilder) DeleteThing() MatchStage
DeleteThing deletes the primary matched variable.
func (MatchBuilder) Fetch
func (b MatchBuilder) Fetch(varName string, attrNames ...string) MatchResultStage
Fetch fetches one or more attributes from a variable.
func (MatchBuilder) Has
func (b MatchBuilder) Has(attrName string, value any) MatchStage
Has adds a has constraint to the primary matched variable.
func (MatchBuilder) Iid
func (b MatchBuilder) Iid(iid string) MatchStage
Iid adds an iid constraint to the primary matched variable.
func (MatchBuilder) InsertHas
func (b MatchBuilder) InsertHas(ownerVar, attrName string, value any) MatchStage
InsertHas emits an explicit has insert statement.
func (MatchBuilder) Let
func (b MatchBuilder) Let(assignments ...LetAssignment) MatchStage
Let appends let assignments to the match clause.
func (MatchBuilder) MatchByIdentifier
func (b MatchBuilder) MatchByIdentifier(identifier, attrName string, matcher IdentifierMatcher) MatchStage
MatchByIdentifier matches by IID (as determined by matcher) or falls back to attribute matching.
func (MatchBuilder) Nodes
func (b MatchBuilder) Nodes() []QueryNode
Nodes returns the compiled AST node sequence before string compilation.
func (MatchBuilder) Or
func (b MatchBuilder) Or(alternatives ...[]Pattern) MatchStage
Or appends an or-pattern with alternatives to the match clause.
func (MatchBuilder) Select
func (b MatchBuilder) Select(vars ...string) MatchResultStage
Select adds a select clause with projected variables.
func (MatchBuilder) Set
func (b MatchBuilder) Set(attrName string, value any) MatchStage
Set emits a standard Match-Delete-Insert sequence for updating one attribute.
func (MatchBuilder) Where
func (b MatchBuilder) Where(patterns ...Pattern) MatchStage
Where appends arbitrary patterns to the match clause.
type MatchClause
MatchClause represents a 'match' clause containing one or more patterns.
type MatchClause struct {
// Patterns are the patterns to match.
Patterns []Pattern
}
func Match
func Match(patterns ...Pattern) MatchClause
Match creates a MatchClause with the given patterns.
type MatchLetClause
MatchLetClause represents a 'match' clause using 'let' assignments.
type MatchLetClause struct {
// Patterns are optional match patterns evaluated before let assignments.
Patterns []Pattern
// Assignments are the let assignments in the clause.
Assignments []LetAssignment
}
type MatchOutputBuilder
MatchOutputBuilder is the concrete immutable output-stage builder for match queries.
type MatchOutputBuilder struct {
// contains filtered or unexported fields
}
func (MatchOutputBuilder) Build
func (b MatchOutputBuilder) Build() (string, error)
Build compiles the fluent query into TypeQL.
func (MatchOutputBuilder) BuildNodes
func (b MatchOutputBuilder) BuildNodes() []QueryNode
BuildNodes returns the compiled AST node sequence before string compilation.
func (MatchOutputBuilder) Fetch
func (b MatchOutputBuilder) Fetch(varName string, attrNames ...string) MatchResultStage
Fetch adds fetch attributes in output stage.
func (MatchOutputBuilder) Limit
func (b MatchOutputBuilder) Limit(count int) MatchResultStage
Limit configures a limit clause in output stage.
func (MatchOutputBuilder) Nodes
func (b MatchOutputBuilder) Nodes() []QueryNode
Nodes returns the compiled AST node sequence before string compilation.
func (MatchOutputBuilder) Offset
func (b MatchOutputBuilder) Offset(count int) MatchResultStage
Offset configures an offset clause in output stage.
func (MatchOutputBuilder) Select
func (b MatchOutputBuilder) Select(vars ...string) MatchResultStage
Select adds a select clause with projected variables in output stage.
func (MatchOutputBuilder) Sort
func (b MatchOutputBuilder) Sort(variable, direction string) MatchResultStage
Sort configures a sort clause in output stage.
type MatchResultStage
MatchResultStage is the output stage for match queries. It supports fetch/select output shaping and pagination/sorting.
type MatchResultStage interface {
Fetch(varName string, attrNames ...string) MatchResultStage
Select(vars ...string) MatchResultStage
Sort(variable, direction string) MatchResultStage
Limit(count int) MatchResultStage
Offset(count int) MatchResultStage
Build() (string, error)
Nodes() []QueryNode
BuildNodes() []QueryNode
}
type MatchStage
MatchStage is the pre-output stage for match queries. It supports matching/mutation operations and can transition to MatchResultStage.
type MatchStage interface {
Has(attrName string, value any) MatchStage
Iid(iid string) MatchStage
MatchByIdentifier(identifier, attrName string, matcher IdentifierMatcher) MatchStage
Where(patterns ...Pattern) MatchStage
Or(alternatives ...[]Pattern) MatchStage
Let(assignments ...LetAssignment) MatchStage
Set(attrName string, value any) MatchStage
DeleteHas(attrVar, ownerVar string) MatchStage
InsertHas(ownerVar, attrName string, value any) MatchStage
DeleteThing() MatchStage
Fetch(varName string, attrNames ...string) MatchResultStage
Select(vars ...string) MatchResultStage
Build() (string, error)
Nodes() []QueryNode
BuildNodes() []QueryNode
}
func FluentMatch
func FluentMatch(varName, typeName string) MatchStage
FluentMatch starts a fluent query with a primary matched variable/type.
func FluentPatterns
func FluentPatterns(patterns ...Pattern) MatchStage
FluentPatterns starts a fluent query from arbitrary match patterns.
type NotPattern
NotPattern represents a negation of one or more patterns (not { ... }).
type NotPattern struct {
// Patterns are the patterns to negate.
Patterns []Pattern
}
type OffsetClause
OffsetClause represents an 'offset' clause for skipping results.
type OffsetClause struct {
// Count is the number of results to skip.
Count int
}
func Offset
func Offset(count int) OffsetClause
Offset creates an OffsetClause with the given count.
type OrPattern
OrPattern represents a disjunction of multiple pattern alternatives ({ ... } or { ... }).
type OrPattern struct {
// Alternatives defines the multiple sets of patterns that satisfy the disjunction.
Alternatives [][]Pattern
}
func Or
func Or(alternatives ...[]Pattern) OrPattern
Or creates an OrPattern from multiple pattern alternatives. Each alternative is a slice of patterns that must all match.
type PaginatedSearchOptions
PaginatedSearchOptions configures PaginatedSearch output and pagination behavior.
type PaginatedSearchOptions struct {
VarName string
Limit int
Offset int
Sort string // "name" for asc, "-name" for desc
FetchIIDKey string
FetchEntityKey string
}
type Pattern
Pattern is the marker interface for patterns used in a match clause.
type Pattern interface {
QueryNode
// contains filtered or unexported methods
}
type PrefixIdentifierMatcher
PrefixIdentifierMatcher considers values with the configured prefix as IIDs.
type PrefixIdentifierMatcher struct {
Prefix string
}
func (PrefixIdentifierMatcher) IsIID
func (m PrefixIdentifierMatcher) IsIID(identifier string) bool
IsIID reports whether identifier matches the configured IID prefix.
type PutClause
PutClause represents a 'put' clause (upsert) containing one or more statements. Put inserts if not exists, or skips if already exists (based on key attributes).
type PutClause struct {
// Statements are the statements defining what to put.
Statements []Statement
}
func Put
func Put(statements ...Statement) PutClause
Put creates a PutClause with the given statements.
type QueryNode
QueryNode is the marker interface for all AST nodes.
type QueryNode interface {
// contains filtered or unexported methods
}
type RawPattern
RawPattern represents a raw TypeQL string pattern, typically for legacy support.
type RawPattern struct {
// Content is the raw TypeQL string.
Content string
}
type RawStatement
RawStatement represents a raw TypeQL string statement.
type RawStatement struct {
// Content is the raw TypeQL string.
Content string
}
type ReduceAssignment
ReduceAssignment represents an assignment in a 'reduce' clause.
type ReduceAssignment struct {
// Variable is the variable receiving the aggregated value.
Variable string
// Expression is the aggregation expression (AggregateExpr or variable string).
Expression any
}
type ReduceClause
ReduceClause represents a 'reduce' clause for performing aggregations in TypeQL.
type ReduceClause struct {
// Assignments are the aggregate assignments.
Assignments []ReduceAssignment
// GroupBy is the optional variable to group the results by.
GroupBy string
}
type RelationPattern
RelationPattern matches a relation with its role players and optional constraints.
type RelationPattern struct {
// Variable is the variable name for the matched relation.
Variable string
// TypeName is the name of the relation type.
TypeName string
// IsStrict indicates whether to use strict type checking (isa!).
IsStrict bool
// RolePlayers defines the participants in the relation.
RolePlayers []RolePlayer
// Constraints are additional constraints applied to the relation.
Constraints []Constraint
}
func Relation
func Relation(varName, typeName string, rolePlayers []RolePlayer, constraints ...Constraint) RelationPattern
Relation creates a RelationPattern with the given variable, type, role players, and constraints.
type RelationStatement
RelationStatement defines a relation and its participants for an insert statement. In TypeDB 3.x, relations in insert statements often don't use a variable prefix.
type RelationStatement struct {
// Variable is the optional variable name for the relation.
Variable string
// TypeName is the name of the relation type.
TypeName string
// RolePlayers defines the participants in the relation.
RolePlayers []RolePlayer
// IncludeVariable indicates whether to include the variable prefix in the compiled query.
IncludeVariable bool
// Attributes are inline attribute assignments for the relation.
Attributes []HasStatement
}
func RelationStmt
func RelationStmt(typeName string, rolePlayers ...RolePlayer) RelationStatement
RelationStmt creates a RelationStatement with the given relation type and role players.
type RolePlayer
RolePlayer represents a role player in a relation, mapping a role name to a player variable.
type RolePlayer struct {
// Role is the name of the role being played.
Role string
// PlayerVar is the variable name of the entity or relation playing the role (e.g., "$p").
PlayerVar string
}
func Role
func Role(roleName, playerVar string) RolePlayer
Role creates a RolePlayer with the given role name and player variable.
type SelectClause
SelectClause represents a 'select' clause for variable projection. Compiles to: select var2, ...;
type SelectClause struct {
// Variables are the variable names to project (e.g., ["$did", "$name"]).
Variables []string
}
func Select
func Select(variables ...string) SelectClause
Select creates a SelectClause for variable projection.
type SortClause
SortClause represents a 'sort' clause for ordering query results.
type SortClause struct {
// Variable is the variable name to sort by (e.g., "$name").
Variable string
// Direction is "asc" or "desc".
Direction string
}
func Sort
func Sort(variable, direction string) SortClause
Sort creates a SortClause for the given variable and direction.
type Statement
Statement is the marker interface for statements used in insert, delete, or update clauses.
type Statement interface {
QueryNode
// contains filtered or unexported methods
}
type SubTypePattern
SubTypePattern matches types that are subtypes of a parent type ($t sub type).
type SubTypePattern struct {
// Variable is the variable representing the subtype.
Variable string
// ParentType is the name of the parent type.
ParentType string
}
type UpdateClause
UpdateClause represents an 'update' clause containing one or more statements.
type UpdateClause struct {
// Statements are the statements defining what to update.
Statements []Statement
}
func Update
func Update(statements ...Statement) UpdateClause
Update creates an UpdateClause with the given statements.
type Value
Value is the marker interface for value nodes that can be used in expressions.
type Value interface {
QueryNode
// contains filtered or unexported methods
}
func ValueFromGo
func ValueFromGo(val any) Value
ValueFromGo converts a Go value to an AST Value node. Handles common types: string, int, int64, float64, bool, time.Time. Falls back to string representation for unknown types.
type ValueComparisonPattern
ValueComparisonPattern represents a comparison between a variable and a value ($v > 10).
type ValueComparisonPattern struct {
// Var is the variable being compared.
Var string
// Operator is the comparison operator (e.g., >, <, ==).
Operator string
// Value is the value to compare against (Value or variable string).
Value any
}
func Cmp
func Cmp(variable, operator string, value any) ValueComparisonPattern
Cmp creates a ValueComparisonPattern for comparing a variable to a value.
Generated by gomarkdoc