Skip to content

Latest commit

 

History

History
1826 lines (1367 loc) · 60.9 KB

File metadata and controls

1826 lines (1367 loc) · 60.9 KB

ast

import "github.com/CaliLuke/go-typeql/v3/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)

DeleteArtifact builds a delete query that matches by IID or fallback attribute.

func DeleteArtifactWithOptions(identifier, typeName string, opts DeleteArtifactOptions) (string, error)

DeleteArtifactWithOptions builds a delete query with custom identifier matching options.

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(value any) string

FormatGoValue converts a Go value into its TypeQL literal string representation. It handles basic types, pointers, and time.Time; common concrete types take a fast path, and reflection is used only for pointers and named/unknown types. This is the canonical formatting function for Go values; other packages should use this instead of implementing their own formatting logic.

func FormatLiteral(val any, valueType string) string

FormatLiteral formats a Go value as a TypeQL literal string. When val does not match valueType (e.g. an int passed as a "string" literal), it falls back to FormatGoValue instead of silently emitting a zero value. The compiler itself reports such mismatches as errors.

A time.Time with valueType "datetime" is stored as UTC: the instant is converted to UTC and emitted as a naive (zone-less) datetime literal with up to nanosecond precision, and hydration parses it back as UTC, so the instant survives round trips. Use "datetime-tz" to keep the value's own offset, or "date" for a date-only literal.

func PaginatedSearch(types []string, opts PaginatedSearchOptions) (string, error)

PaginatedSearch builds a standard typed search with sorting and pagination/fetch options.

func UpdateAttribute(varName, typeName, attrName string, value any) (string, error)

UpdateAttribute builds the standard Match-Delete-Insert sequence for one attribute update.

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 unsupported: TypeQL 3.x reduce aggregates variables only,
    // so setting it produces a compile error. Bind the attribute to a
    // variable in the match clause and aggregate that variable instead.
    AttrName string
}

ArithmeticValue represents a binary arithmetic operation between two values. It supports TypeQL infix operators like +, -, *, /, %, and ^.

type ArithmeticValue struct {
    // Left is the left operand: a Value node, a "$"-prefixed variable
    // string, or a plain Go value (converted via ValueFromGo).
    Left any
    // Operator is the infix operator (+, -, *, /, %, ^).
    Operator string
    // Right is the right operand: a Value node, a "$"-prefixed variable
    // string, or a plain Go value (converted via ValueFromGo).
    Right any
}

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
}

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.

Constraint is the marker interface for constraints applied to variables in a pattern.

type Constraint interface {
    QueryNode
    // contains filtered or unexported methods
}

DeleteArtifactOptions configures DeleteArtifact matching behavior.

type DeleteArtifactOptions struct {
    VarName string
    IDAttr  string
    Matcher IdentifierMatcher
}

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.

DeleteHasStatement represents a statement to delete an attribute from its owner. Compiles to: $attrVar of $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(attrVar, ownerVar string) DeleteHasStatement

DeleteHas creates a DeleteHasStatement for deleting an attribute from its owner. Compiles to: $attrVar of $ownerVar

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
}

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.

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(key, varName, attrName string) FetchAttribute

FetchAttr creates a FetchAttribute for fetching an attribute value. The attrPath should be like "$var.attrname".

func FetchAttrPath(key, attrPath string) FetchAttribute

FetchAttrPath is a convenience for creating FetchAttribute from a dotted path like "$p.name". The path is split at the first dot. A path without a dot (e.g. "$p") is treated as a bare variable and compiles to a plain variable fetch.

func (FetchAttribute) FetchKey

func (f FetchAttribute) FetchKey() string

FetchKey returns the output key for the attribute.

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.

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.

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(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.

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
}

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.

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(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.

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.

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.

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: Value nodes, "$"-prefixed
    // variable strings, or plain Go values (converted via ValueFromGo).
    Args []any
}

func FuncCall(funcName string, args ...any) FunctionCallValue

FuncCall creates a FunctionCallValue with the given function name and arguments.

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.

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
}

FunctionStage is the pre-output stage for function-based match-let queries.

type FunctionStage interface {
    Select(vars ...string) FunctionResultStage
}

func MatchFunction(funcName string, args ...any) FunctionStage

MatchFunction starts a fluent function query compiled as match-let.

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: a Value node, a "$"-prefixed
    // variable string, or a plain Go value (converted via ValueFromGo).
    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 a Value node (Str, Long, ...), a string beginning with "$" (treated as a variable reference), or any other Go value, which is converted via ValueFromGo and emitted as a quoted/escaped TypeQL literal. To match a literal string that begins with "$", wrap it in Str.

HasPattern represents a pattern where a thing has an attribute assignment ($x has Type $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
}

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).

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"}

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.

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
}

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.

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(typeName string) IsaConstraint

IsaExact creates a strict IsaConstraint (isa!) for the given type name.

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.

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
}

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.

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.

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. It returns any deferred builder error (e.g. a constraint that could not be attached) instead of silently dropping the offending clause.

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. It requires the first match pattern to be an EntityPattern (as produced by FluentMatch or an entity-first FluentPatterns); otherwise a deferred error is recorded and returned by Build.

func (MatchBuilder) Iid

func (b MatchBuilder) Iid(iid string) MatchStage

Iid adds an iid constraint to the primary matched variable. Like Has, it requires an entity-first builder; otherwise a deferred error is recorded and returned by Build.

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. Like Has and Iid, it requires an entity-first builder; otherwise a deferred error is recorded and returned by Build.

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.

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.

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
}

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. It returns any deferred builder error carried over from earlier stages.

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.

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
}

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(varName, typeName string) MatchStage

FluentMatch starts a fluent query with a primary matched variable/type.

func FluentPatterns(patterns ...Pattern) MatchStage

FluentPatterns starts a fluent query from arbitrary match patterns.

NotPattern represents a negation of one or more patterns (not { ... }).

type NotPattern struct {
    // Patterns are the patterns to negate.
    Patterns []Pattern
}

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.

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.

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
}

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.

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.

QueryNode is the marker interface for all AST nodes.

type QueryNode interface {
    // contains filtered or unexported methods
}

RawPattern represents a raw TypeQL string pattern, typically for legacy support.

type RawPattern struct {
    // Content is the raw TypeQL string.
    Content string
}

RawStatement represents a raw TypeQL string statement.

type RawStatement struct {
    // Content is the raw TypeQL string.
    Content string
}

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: an AggregateExpr, a Value
    // such as FunctionCallValue, or a raw expression string (e.g. "count($p)").
    Expression any
}

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
}

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(varName, typeName string, rolePlayers []RolePlayer, constraints ...Constraint) RelationPattern

Relation creates a RelationPattern with the given variable, type, role players, and constraints.

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(typeName string, rolePlayers ...RolePlayer) RelationStatement

RelationStmt creates a RelationStatement with the given relation type and role players.

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.

SelectClause represents a 'select' clause for variable projection. Compiles to: select $var1, $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.

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.

Statement is the marker interface for statements used in insert, delete, or update clauses.

type Statement interface {
    QueryNode
    // contains filtered or unexported methods
}

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
}

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(val any) Value

ValueFromGo converts a Go value to an AST Value node. It handles strings, booleans, all integer and unsigned integer widths, floats, time.Time, and (via reflection) pointers and named types of those kinds; other types fall back to their string representation. A nil value (or nil pointer) yields a Value whose compilation fails with a descriptive error rather than silently becoming an empty string.

A time.Time becomes a plain "datetime" value: the instant is stored as UTC and compiles to a naive (zone-less) datetime literal. Use Lit(t, "datetime-tz") or Lit(t, "date") for the other temporal literal kinds.

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: a Value node, a "$"-prefixed
    // variable string, or a plain Go value (converted via ValueFromGo).
    Value any
}

func Cmp

func Cmp(variable, operator string, value any) ValueComparisonPattern

Cmp creates a ValueComparisonPattern for comparing a variable to a value. The value can be a Value node, a string beginning with "$" (treated as a variable reference), or any other Go value, which is converted via ValueFromGo and emitted as a quoted/escaped TypeQL literal.

Generated by gomarkdoc