cypher

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition struct {
	Variable string // "f"
	Property string // "name"
	Operator string // "=", "<>", "=~", "CONTAINS", "STARTS WITH", "ENDS WITH", "IS NULL", "IS NOT NULL", "IN", ">", "<", ">=", "<="
	Value    string // the comparison value (unused for IN, IS NULL, IS NOT NULL)

	// ValueIsString is true when Value came from a string literal. Ordered
	// comparisons (<, >, <=, >=) use it to pick lexicographic vs numeric
	// semantics, matching openCypher's type-aware comparison.
	ValueIsString bool

	// Values holds the list literal for the IN operator: WHERE n.x IN ['a','b'].
	// Empty for all other operators.
	Values []string
}

Condition is a single property comparison.

type Executor

type Executor struct {
	Store   *store.Store
	MaxRows int // 0 means defaultMaxRows

	// MaxUnboundedPathDepth overrides the depth used when a query uses a
	// bare `*` variable-length pattern with no upper bound. Zero means
	// defaultUnboundedPathDepth. The effective cap is always reported on
	// Result.UnboundedDepthCap when the cap fires so callers see when
	// their `*` was clipped.
	MaxUnboundedPathDepth int
	// contains filtered or unexported fields
}

Executor runs Cypher execution plans against a store.

func (*Executor) Execute

func (e *Executor) Execute(query string) (*Result, error)

Execute parses, plans, and executes a Cypher query across all projects.

type ExpandRelationship

type ExpandRelationship struct {
	FromVar   string // source variable (already bound)
	ToVar     string // target variable (to bind)
	RelVar    string // optional relationship variable (to bind edge)
	ToLabel   string // optional label filter on target
	ToProps   map[string]string
	EdgeTypes []string // required edge types
	Direction string   // "outbound", "inbound", "any"
	MinHops   int
	MaxHops   int
}

ExpandRelationship follows edges from bound nodes to match target nodes.

type FilterWhere

type FilterWhere struct {
	Conditions []Condition
	Operator   string // "AND" or "OR"
}

FilterWhere applies WHERE conditions to the bindings.

type Lexer

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

Lexer tokenizes a Cypher query string.

type MatchClause

type MatchClause struct {
	Pattern *Pattern
}

MatchClause holds the MATCH pattern.

type NodePattern

type NodePattern struct {
	Variable string            // e.g. "f"
	Label    string            // e.g. "Function" (optional)
	Props    map[string]string // inline property filters (optional)
}

NodePattern matches a graph node with optional label and inline properties.

type Parser

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

Parser converts a token stream into an AST.

type Pattern

type Pattern struct {
	Elements []PatternElement
}

Pattern is a sequence of alternating nodes and relationships.

type PatternElement

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

PatternElement is either a NodePattern or a RelPattern.

type Plan

type Plan struct {
	Steps      []PlanStep
	ReturnSpec *ReturnClause
}

Plan represents an execution plan for a parsed Cypher query.

func BuildPlan

func BuildPlan(q *Query) (*Plan, error)

BuildPlan converts a parsed Query AST into an execution Plan.

type PlanStep

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

PlanStep is a single step in the execution plan.

type Query

type Query struct {
	Match  *MatchClause
	Where  *WhereClause
	Return *ReturnClause
}

Query represents a parsed Cypher query.

func Parse

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

Parse tokenizes and parses a Cypher query string into an AST.

type RelPattern

type RelPattern struct {
	Variable  string   // (optional)
	Types     []string // relationship types, e.g. ["CALLS", "HTTP_CALLS"]
	Direction string   // "outbound", "inbound", "any"
	MinHops   int      // for variable-length, default 1
	MaxHops   int      // for variable-length, default 1 (0 means unbounded)
}

RelPattern matches a graph relationship with optional types, direction, and hops.

type Result

type Result struct {
	Columns []string         `json:"columns"`
	Rows    []map[string]any `json:"rows"`

	// Truncated is true if any clipping step (final LIMIT/max_rows cap or an
	// intermediate binding-set cap during path expansion) dropped rows. When
	// true, the returned Rows is a sample — not the full matching set. Clients
	// should either raise max_rows, narrow the query with WHERE filters, or
	// shard the query to retrieve the complete result.
	Truncated bool `json:"truncated,omitempty"`

	// EffectiveCap is the row cap that was active for this query. Reflects the
	// lower of (user-supplied max_rows, absoluteMaxRows), defaulting to
	// defaultMaxRows when max_rows is not set. Always populated so clients
	// can report "capped at N" even when Truncated is false.
	EffectiveCap int `json:"effective_cap"`

	// SkippedProjects lists projects whose execution returned an error and
	// were excluded from the merged result. Empty when no projects were
	// skipped. Populating this (instead of silently dropping the project)
	// lets callers see when a single corrupt project DB or transient query
	// failure is shaping the result set.
	SkippedProjects []SkippedProject `json:"skipped_projects,omitempty"`

	// UnboundedDepthCap is set to the depth used when a query uses a bare
	// `*` variable-length pattern and the engine had to apply its default
	// cap. Zero means no unbounded pattern was capped. Callers that issued
	// an unbounded `*` should treat any non-zero value as "this is a
	// sample to depth N — raise MaxUnboundedPathDepth or use an explicit
	// upper bound for full coverage."
	UnboundedDepthCap int `json:"unbounded_depth_cap,omitempty"`
}

Result holds the tabular output of a query.

type ReturnClause

type ReturnClause struct {
	Items    []ReturnItem
	OrderBy  string // "f.name" (optional)
	OrderDir string // "ASC" or "DESC"
	Limit    int    // meaningful only when HasLimit; LIMIT 0 is a valid empty result
	HasLimit bool   // true when an explicit LIMIT clause was present
	Distinct bool
}

ReturnClause specifies which data to return from the query.

type ReturnItem

type ReturnItem struct {
	Variable string // "f"
	Property string // "name" (empty = return whole node)
	Alias    string // "AS call_count" (optional)
	Func     string // "COUNT" / "LABELS" (optional aggregation or function)

	// Distinct is true for COUNT(DISTINCT x) — count unique non-null
	// values of x rather than total bindings. Only meaningful when
	// Func == "COUNT".
	Distinct bool
}

ReturnItem is a single item in the RETURN clause.

type ScanNodes

type ScanNodes struct {
	Variable string
	Label    string
	Props    map[string]string // inline property filters
}

ScanNodes finds nodes matching label and/or inline property filters.

type SkippedProject

type SkippedProject struct {
	Name string `json:"name"`
	Err  string `json:"err"`
}

SkippedProject describes a project that errored during execution and was excluded from the merged result. Err is the error string at the time of skip.

type Token

type Token struct {
	Type  TokenType
	Value string
	Pos   int // byte offset in the input
}

Token is a single lexer token.

func Lex

func Lex(input string) ([]Token, error)

Lex tokenizes the input string into a slice of tokens.

func (Token) String

func (t Token) String() string

type TokenType

type TokenType int

TokenType classifies a lexer token.

const (
	// Keywords
	TokMatch    TokenType = iota // MATCH
	TokWhere                     // WHERE
	TokReturn                    // RETURN
	TokOrder                     // ORDER
	TokBy                        // BY
	TokLimit                     // LIMIT
	TokAnd                       // AND
	TokOr                        // OR
	TokAs                        // AS
	TokDistinct                  // DISTINCT
	TokCount                     // COUNT
	TokContains                  // CONTAINS
	TokStarts                    // STARTS
	TokEnds                      // ENDS
	TokWith                      // WITH
	TokIs                        // IS
	TokNull                      // NULL
	TokNot                       // NOT
	TokIn                        // IN
	TokAsc                       // ASC
	TokDesc                      // DESC

	// Write keywords — reserved for parser-level rejection.
	// code-graph implements a read-only Cypher subset; these are
	// recognized so the parser can produce a clear "not supported in
	// read-only subset" error rather than a confusing "unexpected token"
	// or silent acceptance via trailing-token tolerance.
	TokCreate // CREATE
	TokDelete // DELETE
	TokSet    // SET
	TokMerge  // MERGE
	TokRemove // REMOVE

	// Symbols
	TokLParen   // (
	TokRParen   // )
	TokLBracket // [
	TokRBracket // ]
	TokDash     // -
	TokGT       // >
	TokLT       // <
	TokColon    // :
	TokDot      // .
	TokLBrace   // {
	TokRBrace   // }
	TokStar     // *
	TokComma    // ,
	TokEQ       // =
	TokRegex    // =~
	TokGTE      // >=
	TokLTE      // <=
	TokNEQ      // <>
	TokPipe     // |
	TokDotDot   // ..

	// Literals
	TokIdent  // identifier
	TokString // "..." or '...'
	TokNumber // integer

	TokEOF // end of input
)

type WhereClause

type WhereClause struct {
	Conditions []Condition
	Operator   string // "AND" or "OR"
}

WhereClause holds filter conditions joined by AND/OR.

Jump to

Keyboard shortcuts

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