cypher

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryExpr

type BinaryExpr struct {
	Left  Expr
	Op    string // =, <>, <, >, <=, >=, AND, OR, +, -, *, /, %, IN, CONTAINS, STARTS WITH, ENDS WITH
	Right Expr
}

BinaryExpr represents a binary operation.

type Clause

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

Clause is implemented by all clause types.

type CreateClause

type CreateClause struct {
	Pattern []PathPattern
}

CreateClause represents CREATE.

type DeleteClause

type DeleteClause struct {
	Exprs  []Expr
	Detach bool
}

DeleteClause represents DELETE or DETACH DELETE.

type Direction

type Direction int

Direction for relationships.

const (
	DirRight Direction = iota // ->
	DirLeft                   // <-
	DirBoth                   // --
)

type Executor

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

Executor executes Cypher queries against a graph.

func NewExecutor

func NewExecutor(g *graph.Graph) *Executor

NewExecutor creates a new Cypher executor.

func (*Executor) Execute

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

Execute parses and executes a Cypher query.

func (*Executor) ExecuteAndReturn

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

ExecuteAndReturn is a convenience that parses, executes, and extracts the Result.

type Expr

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

Expr is implemented by all expression types.

type FuncCall

type FuncCall struct {
	Name     string
	Args     []Expr
	Distinct bool
}

FuncCall represents a function call.

type Ident

type Ident struct {
	Name string
}

Ident represents a variable reference.

type IsNullExpr

type IsNullExpr struct {
	Expr   Expr
	Negate bool // IS NOT NULL
}

IsNullExpr represents expr IS NULL or IS NOT NULL.

type Lexer

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

Lexer tokenizes Cypher input.

type ListComprehension

type ListComprehension struct {
	Variable string
	InExpr   Expr
	Where    Expr
	MapExpr  Expr
}

ListComprehension represents [x IN list | expr] or [x IN list WHERE cond | expr].

type ListLiteral

type ListLiteral struct {
	Elements []Expr
}

ListLiteral represents [expr, expr, ...].

type Literal

type Literal struct {
	Value any // string, int64, float64, bool, nil
}

Literal represents a literal value.

type MatchClause

type MatchClause struct {
	Pattern  []PathPattern
	Optional bool
}

MatchClause represents MATCH or OPTIONAL MATCH.

type NodePattern

type NodePattern struct {
	Variable   string
	Labels     []string
	Properties map[string]Expr
}

NodePattern represents (var:Label {props}).

type OrderItem

type OrderItem struct {
	Expr Expr
	Desc bool
}

OrderItem is a single ORDER BY item.

type Parser

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

Parser is a recursive descent parser for Cypher.

type PathPattern

type PathPattern struct {
	Variable string // optional named path
	Elements []PatternElement
}

PathPattern is a sequence of alternating node and relationship patterns.

type PatternElement

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

PatternElement is either a NodePattern or RelPattern.

type PropertyAccess

type PropertyAccess struct {
	Variable string
	Property string
}

PropertyAccess represents var.prop.

type Query

type Query struct {
	Clauses []Clause
}

Query is the top-level AST node.

func Parse

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

Parse parses a Cypher query string into an AST.

type RelPattern

type RelPattern struct {
	Variable  string
	Types     []string
	Direction Direction
	MinHops   *int
	MaxHops   *int
}

RelPattern represents -[var:TYPE*min..max]->

type Result

type Result struct {
	Columns []string
	Rows    []map[string]any
}

Result represents a query result set.

type ReturnClause

type ReturnClause struct {
	Distinct bool
	Items    []ReturnItem
	OrderBy  []OrderItem
	Limit    *Expr
	Skip     *Expr
}

ReturnClause represents RETURN.

type ReturnItem

type ReturnItem struct {
	Expr  Expr
	Alias string
}

ReturnItem is a single item in RETURN.

type SetClause

type SetClause struct {
	Items []SetItem
}

SetClause represents SET.

type SetItem

type SetItem struct {
	Property PropertyAccess
	Value    Expr
}

SetItem is a single SET assignment.

type ShortestPathExpr

type ShortestPathExpr struct {
	Path PathPattern
}

ShortestPathExpr represents shortestPath((a)-[*]-(b)).

type Token

type Token struct {
	Type     TokenType
	Value    string
	Pos      int
	IntVal   int64
	FloatVal float64
}

Token is a lexer token.

func Lex

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

Lex tokenizes the input string.

type TokenType

type TokenType int

TokenType represents the type of a lexer token.

const (
	// Literals
	TokenIdent  TokenType = iota // identifier
	TokenString                  // "string"
	TokenInt                     // 123
	TokenFloat                   // 1.23
	TokenTrue                    // true
	TokenFalse                   // false
	TokenNull                    // null

	// Keywords
	TokenMatch
	TokenOptional
	TokenWhere
	TokenReturn
	TokenCreate
	TokenDelete
	TokenDetach
	TokenSet
	TokenWith
	TokenAs
	TokenOrder
	TokenBy
	TokenLimit
	TokenSkipKw
	TokenAnd
	TokenOr
	TokenNot
	TokenIn
	TokenContains
	TokenStarts
	TokenEnds
	TokenIs
	TokenDistinct
	TokenCount
	TokenCollect
	TokenSum
	TokenAvg
	TokenMin
	TokenMax
	TokenSize
	TokenShortestPath
	TokenDesc
	TokenAsc
	TokenUnwind

	// Symbols
	TokenLParen   // (
	TokenRParen   // )
	TokenLBracket // [
	TokenRBracket // ]
	TokenLBrace   // {
	TokenRBrace   // }
	TokenColon    // :
	TokenDot      // .
	TokenComma    // ,
	TokenPipe     // |
	TokenStar     // *
	TokenDotDot   // ..
	TokenEq       // =
	TokenNeq      // <>
	TokenLt       // <
	TokenGt       // >
	TokenLte      // <=
	TokenGte      // >=
	TokenPlus     // +
	TokenMinus    // -
	TokenSlash    // /
	TokenPercent  // %
	TokenDash     // - (in patterns)
	TokenArrowR   // ->
	TokenArrowL   // <-
	TokenDashDash // --

	TokenEOF
)

type UnaryExpr

type UnaryExpr struct {
	Op   string // NOT, -
	Expr Expr
}

UnaryExpr represents a unary operation.

type UnwindClause

type UnwindClause struct {
	Expr  Expr
	Alias string
}

UnwindClause represents UNWIND.

type WhereClause

type WhereClause struct {
	Expr Expr
}

WhereClause represents WHERE.

type WithClause

type WithClause struct {
	Distinct bool
	Items    []ReturnItem
	Where    *WhereClause
	OrderBy  []OrderItem
	Limit    *Expr
	Skip     *Expr
}

WithClause represents WITH.

Jump to

Keyboard shortcuts

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