matchers

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package matchers provides pattern matching functionality for Cypher queries. It implements the MATCH clause execution by traversing the graph and finding nodes and relationships that match the specified patterns.

The matcher supports:

  • Node pattern matching with labels and properties
  • Relationship pattern matching with types and directions
  • Path traversal through the graph
  • WHERE clause filtering
  • Property comparisons

Example:

matcher := matchers.NewMatcher(store, index)
rows, columns, err := matcher.ExecuteMatch(matchStmt, params)
if err != nil {
    log.Fatal(err)
}
for _, row := range rows {
    fmt.Println(row)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToFloat64

func ToFloat64(v interface{}) (float64, bool)

ToFloat64 converts a value to float64.

Parameters:

  • v: The value to convert

Returns the float64 value and true if conversion succeeded.

Example:

if f, ok := ToFloat64(42); ok {
    fmt.Println(f) // 42.0
}

func ToInt64

func ToInt64(v interface{}) (int64, bool)

ToInt64 converts a value to int64.

Parameters:

  • v: The value to convert

Returns the int64 value and true if conversion succeeded.

Example:

if i, ok := ToInt64(42.5); ok {
    fmt.Println(i) // 42
}

Types

type Matcher

type Matcher struct {
	// Store is the underlying storage database.
	Store *storage.DB

	// Index provides efficient lookups for nodes and relationships.
	Index *graph.Index
}

Matcher executes pattern matching for Cypher MATCH queries. It traverses the graph to find nodes and relationships that match the specified patterns.

func NewMatcher

func NewMatcher(store *storage.DB, index *graph.Index) *Matcher

NewMatcher creates a new Matcher instance.

Parameters:

  • store: The storage database
  • index: The graph index for efficient lookups

Returns a new Matcher instance.

Example:

matcher := matchers.NewMatcher(store, index)

func NewMatcherForMerge added in v0.2.0

func NewMatcherForMerge(store *storage.DB, index *graph.Index) *Matcher

NewMatcherForMerge creates a new Matcher for MERGE operations. This is an alias for NewMatcher.

Parameters:

  • store: The storage database
  • index: The graph index for efficient lookups

Returns a new Matcher instance.

func (*Matcher) EvaluateExpression

func (m *Matcher) EvaluateExpression(path map[string]interface{}, expr ast.Expr, params map[string]interface{}) bool

EvaluateExpression evaluates a WHERE clause expression against a path.

Parameters:

  • path: The matched path containing nodes and relationships
  • expr: The expression to evaluate
  • params: Query parameters

Returns true if the expression evaluates to true for the given path.

func (*Matcher) EvaluateExpressionWithContext added in v0.2.3

func (m *Matcher) EvaluateExpressionWithContext(path map[string]interface{}, expr ast.Expr, params map[string]interface{}, ctxRow map[string]interface{}) bool

func (*Matcher) ExecuteMatch added in v0.2.0

func (m *Matcher) ExecuteMatch(stmt *ast.MatchStmt, params map[string]interface{}) (rows []map[string]interface{}, columns []string, err error)

ExecuteMatch executes a MATCH statement and returns the matched rows.

Parameters:

  • stmt: The MATCH statement AST node
  • params: Query parameters for parameterized queries

Returns the matched rows, column names, and any error encountered.

Example:

rows, columns, err := matcher.ExecuteMatch(matchStmt, map[string]interface{}{
    "name": "Alice",
})

func (*Matcher) ExecuteMatchWithContext added in v0.2.3

func (m *Matcher) ExecuteMatchWithContext(stmt *ast.MatchStmt, params map[string]interface{}, contextRows []map[string]interface{}) (rows []map[string]interface{}, columns []string, err error)

func (*Matcher) ExecutePathForMerge added in v0.2.0

func (m *Matcher) ExecutePathForMerge(path *ast.PathExpr, params map[string]interface{}) ([]map[string]interface{}, error)

func (*Matcher) ExecuteUnwind added in v0.2.3

func (m *Matcher) ExecuteUnwind(stmt *ast.UnwindStmt, params map[string]interface{}) (rows []map[string]interface{}, columns []string, err error)

func (*Matcher) ProcessReturnStmt added in v0.2.3

func (m *Matcher) ProcessReturnStmt(rows []map[string]interface{}, returnExpr *ast.ReturnExpr) ([]map[string]interface{}, []string, error)

func (*Matcher) PropertyToInterface

func (m *Matcher) PropertyToInterface(prop graph.PropertyValue) interface{}

PropertyToInterface converts a PropertyValue to a Go interface{}. Delegates to graph.PropertyValue.InterfaceValue().

Jump to

Keyboard shortcuts

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