opencypher

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

README

GoDoc Go Report Card Build Status

Embedded openCypher interpreter

openCypher is a query language for labeled property graphs. This Go module contains an openCypher interpreter (partial) that works on the Go LPG implementation given in https://github.com/cloudprivacylabs/lpg.

More information on openCypher can be found here:

https://opencypher.org/

openCypher

At this point, this library provides partial support for openCypher expressions. More support will be added as needed.

openCypher expressions are evaluated using an evaluation context.

Create Nodes

See examples/create directory.

import (
	"fmt"

	"github.com/cloudprivacylabs/opencypher"
	"github.com/cloudprivacylabs/lpg"
)

func main() {
	grph := graph.NewGraph()
	ectx := opencypher.NewEvalContext(grph)
	_, err := opencypher.ParseAndEvaluate(`CREATE (n:Person), (m)`, ectx)
	if err != nil {
		panic(err)
	}
	v, err := opencypher.ParseAndEvaluate(`MATCH (x:Person) return x as person`, ectx)
	if err != nil {
		panic(err)
	}
	fmt.Println(v.Rows[0]["person"])
}
Evaluation Context

Variables defined in an expression will be in the evaluation context, and can be used to affect the results of subsequent expression.

See examples/context.

func main() {
	// Create an empty graph
	grph := graph.NewGraph()
	// Evaluation context knows the graph we are working on
	ectx := opencypher.NewEvalContext(grph)
	// CREATE a path
	_, err := opencypher.ParseAndEvaluate(`CREATE (andy {name:"Andy"})-[:KNOWS]-> (stephen {name:"Stephen"})`, ectx)
	if err != nil {
		panic(err)
	}
	// ectx knows andy and stephen. So this will only update stephen, and not andy
	v, err := opencypher.ParseAndEvaluate(`MATCH (stephen) SET stephen.age=34 return stephen`, ectx)
	if err != nil {
		panic(err)
	}
	age, _ := v.Rows[0]["1"].Get().(*graph.Node).GetProperty("age")
	fmt.Println(age) // This will print 34
}
Querying and result sets

Using the example in https://neo4j.com/docs/cypher-manual/current/clauses/match/

	// Get all nodes
	ectx = opencypher.NewEvalContext(grph)
	res, err := opencypher.ParseAndEvaluate(`match (n) return n`, ectx)
	fmt.Println("match (n) return n:", res.Rows)

	// Get all movies
	ectx = opencypher.NewEvalContext(grph)
	res, err = opencypher.ParseAndEvaluate(`match (n:Movie) return n.title`, ectx)
	fmt.Println("match (n:Movie) return n.title:", res.Rows)

	// Get related node
	ectx = opencypher.NewEvalContext(grph)
	res, err = opencypher.ParseAndEvaluate(`match (director {name: 'Oliver Stone'}) --(movie:Movie) return movie.title`, ectx)
	fmt.Println("match (director {name: 'Oliver Stone'}) --(movie:Movie) return movie.title:", res.Rows)
	ectx = opencypher.NewEvalContext(grph)
	res, err = opencypher.ParseAndEvaluate(`match (director {name: 'Oliver Stone'}) --> (movie:Movie) return movie.title`, ectx)
	fmt.Println("match (director {name: 'Oliver Stone'}) --> (movie:Movie) return movie.title:", res.Rows)

	// Get relationship type
	ectx = opencypher.NewEvalContext(grph)
	res, err = opencypher.ParseAndEvaluate(`match (:Person {name: 'Oliver Stone'}) -[r]->(movie) return r`, ectx)
	fmt.Println("match (:Person {name: 'Oliver Stone'}) -[r]->(movie) return r:", res.Rows)
Values

OpenCypher expressions returns Values. Queries return ResultSetProvider instances. Top-level APIs will return ResultSet objects, which is a tabular representation of the result of the operation. A ResultSet contains Rows that are map[string]Value objects. If the query explicitly names its columns, the map will contains those names as the keys. Otherwise, the columns will be "1", "2", etc.

The number of rows in the result set:

numResults:=len(rs.Rows)

Iterate the results:

for _,row := range resultSet.Rows {
   for colName, colValue := range row {
      // colName is the column name
      // colValue is an opencypher.Value object
      fmt.Println(colName,value.Get())
   }
}

The return type of Value.Get is one of the following:

  • int
  • float64
  • bool
  • string
  • Duration
  • Date
  • Time
  • LocalDateTime
  • LocalTime
  • []Value
  • map[string]Value
  • lpg.StringSet
  • *lpg.Node
  • []*lpg.Edge
  • ResultSet

This Go module is part of the Layered Schema Architecture.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAdditiveOperation       = errors.New("Invalid additive operation")
	ErrInvalidDateOperation           = errors.New("Invalid date operation")
	ErrInvalidDurationOperation       = errors.New("Invalid duration operation")
	ErrInvalidStringOperation         = errors.New("Invalid string operation")
	ErrInvalidMultiplicativeOperation = errors.New("Invalid multiplicative operation")
	ErrInvalidDivisionOperation       = errors.New("Invalid division operation")
	ErrInvalidModOperation            = errors.New("Invalid mod operation")
	ErrDivideByZero                   = errors.New("Divide by zero")
	ErrInvalidUnaryOperation          = errors.New("Invalid unary operation")
	ErrInvalidPowerOperation          = errors.New("Invalid power operation")
)
View Source
var (
	AdditionOperator AdditiveOperator = additionOperator{
						// contains filtered or unexported fields
	}
	SubtractionOperator AdditiveOperator = subtractionOperator{
						// contains filtered or unexported fields
	}
	MultiplicationOperator MultiplicativeOperator = multiplyOperator{
							// contains filtered or unexported fields
	}
	DivisionOperator MultiplicativeOperator = divideOperator{
						// contains filtered or unexported fields
	}
	ModOperator MultiplicativeOperator = modOperator{
				// contains filtered or unexported fields
	}
)
View Source
var (
	ErrNotABooleanExpression = errors.New("Not a boolean expression")
	ErrNotAStringExpression  = errors.New("Not a string expression")
	ErrIntRequired           = errors.New("Integer value required")
	ErrNotAList              = errors.New("Not a list")
	ErrNotANode              = errors.New("Not a node")
	ErrParameterNotAnObject  = errors.New("Parameter value is not an object")
	ErrInvalidComparison     = errors.New("Invalid comparison")
	ErrNotAnObject           = errors.New("Not an object")
)
View Source
var (
	ErrInvalidRelationshipPattern = errors.New("Invalid relationship pattern")
	ErrCannotDeleteAttachedNode   = errors.New("Cannot delete attached node")
	ErrLValueRequired             = errors.New("lvalue required")
	ErrNoBoundNodes               = errors.New("No bound nodes in the match expression")
	ErrNotAnEdge                  = errors.New("Not a relationship")
	ErrBoundEdgeInMergeClause     = errors.New("Bound edge in merge clause")
	ErrEdgeHasMultipleLabels      = errors.New("Edge has multiple labels")
	ErrEdgeHasRange               = errors.New("Edge has a range")
)
View Source
var ErrColumnsHaveDifferentNames = errors.New("Columns have different names")
View Source
var ErrColumnsHaveDifferentTypes = errors.New("Columns have different types")
View Source
var ErrCursorsHaveDifferentSizes = errors.New("Cursors have different number of columns")
View Source
var ErrInvalidMapKey = errors.New("Invalid map key")

Functions

func GetAllRows

func GetAllRows(rs Cursor) ([][]Value, error)

func GetParser

func GetParser(input string) *parser.CypherParser

GetParser returns a parser that will parse the input string

func IsPrimitive

func IsPrimitive(v any) bool

IsPrimitive returns true if the value is int, float64, bool, string, duration, date, datetime, localDateTime, or localTime

func OC_AnonymousPatternPart

func OC_AnonymousPatternPart(ctx *parser.OC_AnonymousPatternPartContext, part *PatternPart) error

oC_AnonymousPatternPart: oC_PatternElement ;

func OC_FunctionName

func OC_FunctionName(ctx *parser.OC_FunctionNameContext) (namespace, name string)

func OC_Namespace

func OC_Namespace(ctx *parser.OC_NamespaceContext) string

func OC_NodeLabels

func OC_NodeLabels(ctx *parser.OC_NodeLabelsContext) []string

func OC_PatternElement

func OC_PatternElement(ctx *parser.OC_PatternElementContext, part *PatternPart) error

oC_PatternElement:

( oC_NodePattern ( SP? oC_PatternElementChain )* ) | ( '(' oC_PatternElement ')' )

func OC_ProcedureName

func OC_ProcedureName(ctx *parser.OC_ProcedureNameContext) (namespace, name string)

func OC_PropertyKeyName

func OC_PropertyKeyName(ctx *parser.OC_PropertyKeyNameContext) string

func OC_PropertyLookup

func OC_PropertyLookup(ctx *parser.OC_PropertyLookupContext) string

func OC_RelTypeName

func OC_RelTypeName(ctx *parser.OC_RelTypeNameContext) string

func OC_RelationshipTypes

func OC_RelationshipTypes(ctx *parser.OC_RelationshipTypesContext) []string

oC_RelationshipTypes: ':' SP? oC_RelTypeName ( SP? '|' ':'? SP? oC_RelTypeName )* ;

func OC_ReservedWord

func OC_ReservedWord(ctx *parser.OC_ReservedWordContext) string

func OC_SchemaName

func OC_SchemaName(ctx *parser.OC_SchemaNameContext) string

func OC_StringOperatorExpression

func OC_StringOperatorExpression(ctx *parser.OC_StringOperatorExpressionContext) (op StringOperator, expr Expression, err error)

oC_StringOperatorExpression:

( ( SP STARTS SP WITH ) | ( SP ENDS SP WITH ) | ( SP CONTAINS ) ) SP? oC_PropertyOrLabelsExpression ;

func OC_SymbolicName

func OC_SymbolicName(ctx *parser.OC_SymbolicNameContext) string

func OC_Variable

func OC_Variable(ctx *parser.OC_VariableContext) string

func RegisterGlobalFunc

func RegisterGlobalFunc(fn ...Function)

func RegisterGlobalProc

func RegisterGlobalProc(ps ...Procedure)

func ResultRowToContext

func ResultRowToContext(row []Value, rs CursorColumns, target *EvalContext)

Types

type AddOrSubtractExpression

type AddOrSubtractExpression struct {
	Expr       []Expression
	Op         []AdditiveOperator
	ResultType ValueType
}

expr[0] op[0] expr[1] op[1] expr[2] ...

func (*AddOrSubtractExpression) Constraints

func (expr *AddOrSubtractExpression) Constraints(ctx *EvalContext) Constraint

func (*AddOrSubtractExpression) Evaluate

func (expr *AddOrSubtractExpression) Evaluate(ctx *EvalContext) (Value, error)

func (AddOrSubtractExpression) Tree

func (expr AddOrSubtractExpression) Tree() any

func (AddOrSubtractExpression) Type

func (expr AddOrSubtractExpression) Type() ValueType

type AdditiveOperator

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

type AndExpression

type AndExpression struct {
	Parts []Expression
}

func (*AndExpression) Constraints

func (expr *AndExpression) Constraints(ctx *EvalContext) Constraint

func (*AndExpression) Evaluate

func (expr *AndExpression) Evaluate(ctx *EvalContext) (Value, error)

func (AndExpression) Tree

func (expr AndExpression) Tree() any

func (AndExpression) Type

func (AndExpression) Type() ValueType

type BasicCursor

type BasicCursor struct {
	Cols BasicCursorColumns
	Rows [][]Value
	At   int
}

BasicCursor keeps all its rows and cols

func (BasicCursor) Column

func (set BasicCursor) Column(index int) CursorColumn

func (BasicCursor) Err

func (set BasicCursor) Err() error

func (BasicCursor) Len

func (set BasicCursor) Len() int

func (BasicCursor) NColumns

func (set BasicCursor) NColumns() int

func (*BasicCursor) Next

func (set *BasicCursor) Next() bool

func (*BasicCursor) Row

func (set *BasicCursor) Row() []Value

type BasicCursorColumns

type BasicCursorColumns []CursorColumn

func NewBasicCursorColumns

func NewBasicCursorColumns(in CursorColumns) BasicCursorColumns

func (BasicCursorColumns) Column

func (b BasicCursorColumns) Column(index int) CursorColumn

func (BasicCursorColumns) NColumns

func (b BasicCursorColumns) NColumns() int

type CaseAlternative

type CaseAlternative struct {
	When Expression
	Then Expression
}

type CaseClause

type CaseClause struct {
	Test         Expression
	Alternatives []CaseAlternative
	Default      Expression
	ResultType   ValueType
}

func (*CaseClause) Constraints

func (expr *CaseClause) Constraints(ctx *EvalContext) Constraint

func (*CaseClause) Evaluate

func (expr *CaseClause) Evaluate(ctx *EvalContext) (Value, error)

func (CaseClause) Tree

func (expr CaseClause) Tree() any

func (CaseClause) Type

func (expr CaseClause) Type() ValueType

type ComparisonExpression

type ComparisonExpression struct {
	Left Expression
	// Op accepts the result of the comparison as <0, 0, >0, and returns the comparison result
	Op    func(int) bool
	OpStr string
	Right Expression
}

func (*ComparisonExpression) Constraints

func (expr *ComparisonExpression) Constraints(ctx *EvalContext) Constraint

func (*ComparisonExpression) Evaluate

func (expr *ComparisonExpression) Evaluate(ctx *EvalContext) (Value, error)

func (ComparisonExpression) Tree

func (expr ComparisonExpression) Tree() any

func (ComparisonExpression) Type

type ConjunctiveConstraint

type ConjunctiveConstraint struct {
	Parts []Constraint
}

func (ConjunctiveConstraint) BuildFilter

func (c ConjunctiveConstraint) BuildFilter(varName string) map[string]PropertyCriteria

func (ConjunctiveConstraint) CanInvert

func (c ConjunctiveConstraint) CanInvert() bool

func (ConjunctiveConstraint) Invert

func (c ConjunctiveConstraint) Invert() Constraint

type Constraint

type Constraint interface {
	CanInvert() bool
	Invert() Constraint
	BuildFilter(varName string) map[string]PropertyCriteria
	// contains filtered or unexported methods
}

type ConstraintOperator

type ConstraintOperator int
const (
	NoConstraintOperator ConstraintOperator = iota
)

type CreateClause

type CreateClause struct {
	Pattern Pattern
}

func (CreateClause) Tree

func (c CreateClause) Tree() any

func (*CreateClause) Update

func (clause *CreateClause) Update(ctx *EvalContext, input Cursor) (Cursor, error)

type Cursor

type Cursor interface {
	CursorColumns
	// Move to next item
	Next() bool
	// Return the row values for the current item Implementations should
	// lazy initialize this as Row() may be called multiple times for a
	// single row.
	Row() []Value

	// If length is unknown, returns -1
	Len() int

	Err() error
}

func ParseAndEvaluate

func ParseAndEvaluate(input string, ctx *EvalContext) (Cursor, error)

type CursorColumn

type CursorColumn struct {
	Type  ValueType
	Name  string
	Index int
}

func (CursorColumn) IsCompatible

func (c CursorColumn) IsCompatible(col CursorColumn) error

type CursorColumns

type CursorColumns interface {
	NColumns() int
	Column(int) CursorColumn
}

type Date

type Date time.Time // Date value, without a time zone and time related components.

func NewDate

func NewDate(t time.Time) Date

NewDate creates a Date Hour, minute, second and nanoseconds are set to zero and location is set to UTC.

func (Date) String

func (t Date) String() string

func (Date) Time

func (t Date) Time() time.Time

Time casts Date to time.Time

type DeleteClause

type DeleteClause struct {
	Detach bool
	Exprs  []Expression
}

func (DeleteClause) Tree

func (d DeleteClause) Tree() any

func (*DeleteClause) Update

func (del *DeleteClause) Update(ctx *EvalContext, input Cursor) (Cursor, error)

type DisjunctiveConstraint

type DisjunctiveConstraint struct {
	Parts []Constraint
}

func (DisjunctiveConstraint) BuildFilter

func (c DisjunctiveConstraint) BuildFilter(varName string) map[string]PropertyCriteria

func (DisjunctiveConstraint) CanInvert

func (c DisjunctiveConstraint) CanInvert() bool

func (DisjunctiveConstraint) Invert

func (c DisjunctiveConstraint) Invert() Constraint

type Duration

type Duration struct {
	Months  int64
	Days    int64
	Seconds int64
	Nanos   int
}

Duration represents a duration in opencypher. Copied from neo4j driver.

func (Duration) Equal

func (d1 Duration) Equal(d2 Duration) bool

func (Duration) String

func (d Duration) String() string

type Edge

type Edge interface {
	ID() any
	From() Node
	To() Node
	Label() string
	SetLabel(string)

	GetProperty(string) Value
	SetProperty(string, Value)
	RemoveProperty(string)
	SetProperties(map[string]Value)
	GetProperties() map[string]Value
}

type EdgeCriteria

type EdgeCriteria struct {
	Name string

	Dir EdgeDirection
	// The edges must have this label
	MustHaveLabel string
	// The edges must have at least one of these labels
	AtLeastOneLabel []string

	// Criteria for the properties
	Properties map[string]PropertyCriteria

	Min int
	Max int
}

type EdgeDirection

type EdgeDirection int
const (
	EdgeDirectionRight EdgeDirection = iota
	EdgeDirectionLeft
	EdgeDirectionNone
)

type ElementAccessExpression

type ElementAccessExpression struct {
	Left Expression
	Key  Expression
}

func (*ElementAccessExpression) Constraints

func (expr *ElementAccessExpression) Constraints(ctx *EvalContext) Constraint

func (*ElementAccessExpression) Evaluate

func (expr *ElementAccessExpression) Evaluate(ctx *EvalContext) (Value, error)

func (ElementAccessExpression) Tree

func (expr ElementAccessExpression) Tree() any

func (ElementAccessExpression) Type

type ErrColumnsIncompatible

type ErrColumnsIncompatible struct {
	Index int
	Err   error
}

func (ErrColumnsIncompatible) Error

func (e ErrColumnsIncompatible) Error() string

func (ErrColumnsIncompatible) Unwrap

func (e ErrColumnsIncompatible) Unwrap() error

type ErrInvalidExpression

type ErrInvalidExpression struct {
	Expr string
}

func (ErrInvalidExpression) Error

func (e ErrInvalidExpression) Error() string

type ErrInvalidFunctionCall

type ErrInvalidFunctionCall struct {
	Msg string
}

func (ErrInvalidFunctionCall) Error

func (e ErrInvalidFunctionCall) Error() string

type ErrInvalidIndirection

type ErrInvalidIndirection struct {
	Name string
}

func (ErrInvalidIndirection) Error

func (err ErrInvalidIndirection) Error() string

type ErrInvalidListIndex

type ErrInvalidListIndex struct {
	Index any
}

func (ErrInvalidListIndex) Error

func (err ErrInvalidListIndex) Error() string

type ErrNodeAlreadyDefined

type ErrNodeAlreadyDefined struct {
	Name string
}

func (ErrNodeAlreadyDefined) Error

func (e ErrNodeAlreadyDefined) Error() string

type ErrNodeValueRequired

type ErrNodeValueRequired struct {
	Name string
}

func (ErrNodeValueRequired) Error

func (e ErrNodeValueRequired) Error() string

type ErrResultFieldNotFound

type ErrResultFieldNotFound struct {
	Name string
}

func (ErrResultFieldNotFound) Error

func (err ErrResultFieldNotFound) Error() string

type ErrSyntax

type ErrSyntax string

func (ErrSyntax) Error

func (e ErrSyntax) Error() string

type ErrUnknownFunction

type ErrUnknownFunction struct {
	Name string
}

func (ErrUnknownFunction) Error

func (e ErrUnknownFunction) Error() string

type ErrUnknownParameter

type ErrUnknownParameter struct {
	Key string
}

func (ErrUnknownParameter) Error

func (e ErrUnknownParameter) Error() string

type ErrUnknownProcedure

type ErrUnknownProcedure struct {
	Name string
}

func (ErrUnknownProcedure) Error

func (err ErrUnknownProcedure) Error() string

type ErrUnknownVariable

type ErrUnknownVariable struct {
	Name string
}

func (ErrUnknownVariable) Error

func (e ErrUnknownVariable) Error() string

type ErrVarRedefined

type ErrVarRedefined struct {
	Name string
}

func (ErrVarRedefined) Error

func (e ErrVarRedefined) Error() string

type ErrorListener

type ErrorListener struct {
	antlr.DefaultErrorListener
	// contains filtered or unexported fields
}

func (*ErrorListener) Err

func (lst *ErrorListener) Err() error

func (*ErrorListener) SyntaxError

func (lst *ErrorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException)

type EvalContext

type EvalContext struct {
	context.Context
	// contains filtered or unexported fields
}

func NewEvalContext

func NewEvalContext(graph Graph) *EvalContext

func (*EvalContext) GetFunction

func (ctx *EvalContext) GetFunction(namespace, name string) (Function, error)

func (*EvalContext) GetParameter

func (ctx *EvalContext) GetParameter(key string) (Value, error)

func (*EvalContext) GetVar

func (ctx *EvalContext) GetVar(name string) (Value, error)

func (*EvalContext) RemoveVar

func (ctx *EvalContext) RemoveVar(name string)

func (*EvalContext) SetParameter

func (ctx *EvalContext) SetParameter(key string, value Value) *EvalContext

SetParameter sets a parameter to be used in expressions

func (*EvalContext) SetVar

func (ctx *EvalContext) SetVar(name string, value Value)

func (*EvalContext) String

func (ctx *EvalContext) String() string

func (*EvalContext) SubContext

func (ctx *EvalContext) SubContext() *EvalContext

SubContext creates a new subcontext with a new variable set

func (*EvalContext) VarDefined

func (ctx *EvalContext) VarDefined(name string) bool

func (*EvalContext) WithContext

func (ctx *EvalContext) WithContext(c context.Context) *EvalContext

Returns ctx with the new context

type Expression

type Expression interface {
	Evaluate(*EvalContext) (Value, error)
	Constraints(*EvalContext) Constraint
	Type() ValueType
	Tree() any
	// contains filtered or unexported methods
}

An Expression produces a value

func OC_AddOrSubtractExpression

func OC_AddOrSubtractExpression(ctx *parser.OC_AddOrSubtractExpressionContext) (Expression, error)

oC_AddOrSubtractExpression :

oC_MultiplyDivideModuloExpression (
     ( SP? '+' SP? oC_MultiplyDivideModuloExpression ) |
     ( SP? '-' SP? oC_MultiplyDivideModuloExpression )
)*

func OC_AndExpression

func OC_AndExpression(ctx *parser.OC_AndExpressionContext) (Expression, error)

oC_AndExpression : oC_NotExpression ( SP AND SP oC_NotExpression )* ;

func OC_Atom

func OC_Atom(ctx *parser.OC_AtomContext) (Expression, error)

oC_Atom: oC_Literal | oC_Parameter | oC_CaseExpression | ( COUNT SP? '(' SP? '*' SP? ')' ) | oC_ListComprehension | oC_PatternComprehension | ( ALL SP? '(' SP? oC_FilterExpression SP? ')' ) (all (x in list where predicate)) true if pred holds for all elems | ( ANY SP? '(' SP? oC_FilterExpression SP? ')' ) (any (x in list where predicate)) true if pred holds for at least one | ( NONE SP? '(' SP? oC_FilterExpression SP? ')' ) (none (x in list where predicate)) true if pred holds for none | ( SINGLE SP? '(' SP? oC_FilterExpression SP? ')' ) (single (x in list where predicate)) true if pred holds for one | oC_RelationshipsPattern | oC_ParenthesizedExpression | oC_FunctionInvocation | oC_Variable

func OC_BooleanLiteral

func OC_BooleanLiteral(ctx *parser.OC_BooleanLiteralContext) Expression

func OC_CaseExpression

func OC_CaseExpression(ctx *parser.OC_CaseExpressionContext) (Expression, error)

func OC_ComparisonExpression

func OC_ComparisonExpression(ctx *parser.OC_ComparisonExpressionContext) (Expression, error)

oC_ComparisonExpression: oC_AddOrSubtractExpression ( SP? oC_PartialComparisonExpression )* ; oC_PartialComparisonExpression:

( '=' SP? oC_AddOrSubtractExpression )
  | ( '<>' SP? oC_AddOrSubtractExpression )
  | ( '<' SP? oC_AddOrSubtractExpression )
  | ( '>' SP? oC_AddOrSubtractExpression )
  | ( '<=' SP? oC_AddOrSubtractExpression )
  | ( '>=' SP? oC_AddOrSubtractExpression )

func OC_DoubleLiteral

func OC_DoubleLiteral(ctx *parser.OC_DoubleLiteralContext) (Expression, error)

func OC_Expression

func OC_Expression(ctx *parser.OC_ExpressionContext) (Expression, error)

oC_Expression: oC_OrExpression ;

func OC_FunctionInvocation

func OC_FunctionInvocation(ctx *parser.OC_FunctionInvocationContext) (Expression, error)

oC_FunctionInvocation:

oC_FunctionName SP? '(' SP? ( DISTINCT SP? )? ( oC_Expression SP? ( ',' SP? oC_Expression SP? )* )? ')' ;

func OC_IntegerLiteral

func OC_IntegerLiteral(ctx *parser.OC_IntegerLiteralContext) (Expression, error)

oC_IntegerLiteral:

HexInteger
  | OctalInteger
  | DecimalInteger

func OC_Limit

func OC_Limit(ctx *parser.OC_LimitContext) (Expression, error)

func OC_ListComprehension

func OC_ListComprehension(ctx *parser.OC_ListComprehensionContext) (Expression, error)

oC_ListComprehension : '[' SP? oC_FilterExpression ( SP? '|' SP? oC_Expression )? SP? ']' ;

func OC_ListLiteral

func OC_ListLiteral(ctx *parser.OC_ListLiteralContext) (Expression, error)

func OC_ListOperatorExpression

func OC_ListOperatorExpression(ctx *parser.OC_ListOperatorExpressionContext) (in, e1, e2 Expression, err error)

oC_ListOperatorExpression:

( SP IN SP? oC_PropertyOrLabelsExpression ) | ( SP? '[' oC_Expression ']' ) | ( SP? '[' oC_Expression? '..' oC_Expression? ']' );

func OC_Literal

func OC_Literal(ctx *parser.OC_LiteralContext) (Expression, error)

func OC_MapLiteral

func OC_MapLiteral(ctx *parser.OC_MapLiteralContext) (Expression, error)

func OC_MultiplyDivideModuloExpression

func OC_MultiplyDivideModuloExpression(ctx *parser.OC_MultiplyDivideModuloExpressionContext) (Expression, error)

oC_MultiplyDivideModuloExpression :

oC_PowerOfExpression (
    ( SP? '*' SP? oC_PowerOfExpression ) |
    ( SP? '/' SP? oC_PowerOfExpression ) |
    ( SP? '%' SP? oC_PowerOfExpression ) )* ;

func OC_NotExpression

func OC_NotExpression(ctx *parser.OC_NotExpressionContext) (Expression, error)

oC_NotExpression: ( NOT SP? )* oC_ComparisonExpression ;

func OC_NumberLiteral

func OC_NumberLiteral(ctx *parser.OC_NumberLiteralContext) (Expression, error)

func OC_OrExpression

func OC_OrExpression(ctx *parser.OC_OrExpressionContext) (Expression, error)

oC_OrExpression : oC_XorExpression ( SP OR SP oC_XorExpression )* ;

func OC_Parameter

func OC_Parameter(ctx *parser.OC_ParameterContext) Expression

func OC_PowerOfExpression

func OC_PowerOfExpression(ctx *parser.OC_PowerOfExpressionContext) (Expression, error)

oC_PowerOfExpression :

oC_UnaryAddOrSubtractExpression ( SP? '^' SP? oC_UnaryAddOrSubtractExpression )* ;

func OC_PropertyExpression

func OC_PropertyExpression(ctx *parser.OC_PropertyExpressionContext) (Expression, error)

oC_PropertyExpression : oC_Atom ( SP? oC_PropertyLookup )+ ; Property expression names a property expression, it is not an lvalue

func OC_PropertyOrLabelsExpression

func OC_PropertyOrLabelsExpression(ctx *parser.OC_PropertyOrLabelsExpressionContext) (Expression, error)

oC_PropertyOrLabelsExpression : oC_Atom ( SP? oC_PropertyLookup )* ( SP? oC_NodeLabels )? ;

func OC_Skip

func OC_Skip(ctx *parser.OC_SkipContext) (Expression, error)

func OC_StringListNullOperatorExpression

func OC_StringListNullOperatorExpression(ctx *parser.OC_StringListNullOperatorExpressionContext) (Expression, error)

oC_StringListNullOperatorExpression:

oC_PropertyOrLabelsExpression ( oC_StringOperatorExpression | oC_ListOperatorExpression | oC_NullOperatorExpression )* ;

func OC_UnaryAddOrSubtractExpression

func OC_UnaryAddOrSubtractExpression(ctx *parser.OC_UnaryAddOrSubtractExpressionContext) (Expression, error)

oC_UnaryAddOrSubtractExpression: ( ( '+' | '-' ) SP? )* oC_StringListNullOperatorExpression ;

func OC_Where

func OC_Where(ctx *parser.OC_WhereContext) (Expression, error)

func OC_XorExpression

func OC_XorExpression(ctx *parser.OC_XorExpressionContext) (Expression, error)

oC_XorExpression : oC_AndExpression ( SP XOR SP oC_AndExpression )* ;

type FilterExpression

type FilterExpression struct {
	Variable string
	InExpr   Expression
	Where    Expression
}

func OC_FilterExpression

func OC_FilterExpression(ctx *parser.OC_FilterExpressionContext) (*FilterExpression, error)

oC_FilterExpression : oC_IdInColl ( SP? oC_Where )? ; oC_IdInColl : oC_Variable SP IN SP oC_Expression ;

func (FilterExpression) Tree

func (expr FilterExpression) Tree() any

func (FilterExpression) Type

func (FilterExpression) Type() ValueType

type Function

type Function struct {
	Name    string
	MinArgs int
	MaxArgs int
	// If true, function does not have side effects
	Pure      bool
	Func      func(*EvalContext, []Expression) (Value, error)
	ValueFunc func(*EvalContext, []Value) (Value, error)
}

Function describes a function

type FunctionInvocationExpression

type FunctionInvocationExpression struct {
	Namespace string
	Name      string
	Distinct  bool
	Args      []Expression
}

func (*FunctionInvocationExpression) Constraints

func (expr *FunctionInvocationExpression) Constraints(ctx *EvalContext) Constraint

func (*FunctionInvocationExpression) Evaluate

func (expr *FunctionInvocationExpression) Evaluate(ctx *EvalContext) (Value, error)

func (FunctionInvocationExpression) Tree

func (expr FunctionInvocationExpression) Tree() any

func (FunctionInvocationExpression) Type

type Graph

type Graph interface {
	SearchPattern(*EvalContext, PathCriteria) (GraphCursor, error)
	NewEdge(from, to Node, label string, properties map[string]Value) (Edge, error)
	NewNode([]string, map[string]Value) (Node, error)
	DeleteEdge(Edge) error
	DetachDeleteNode(Node) error
}

type GraphCursor

type GraphCursor interface {
	Next() bool
	Path() Path
	// Return the value of the symbol in the current element
	SymbolValue(string) Value
	Err() error
	Close()
}

A GraphCursor over the results of a patterh search. Cursor must be closed when done.

type InExpression

type InExpression struct {
	Left Expression
	List Expression
}

func (*InExpression) Constraints

func (expr *InExpression) Constraints(ctx *EvalContext) Constraint

func (*InExpression) Evaluate

func (expr *InExpression) Evaluate(ctx *EvalContext) (Value, error)

func (InExpression) Tree

func (expr InExpression) Tree() any

func (InExpression) Type

func (InExpression) Type() ValueType

type LPGEdge

type LPGEdge struct {
	Edge *lpg.Edge
}

func (LPGEdge) From

func (edge LPGEdge) From() Node

func (LPGEdge) GetProperties

func (edge LPGEdge) GetProperties() map[string]Value

func (LPGEdge) GetProperty

func (edge LPGEdge) GetProperty(name string) Value

func (LPGEdge) ID

func (edge LPGEdge) ID() any

func (LPGEdge) Label

func (edge LPGEdge) Label() string

func (LPGEdge) RemoveProperty

func (edge LPGEdge) RemoveProperty(name string)

func (LPGEdge) SetLabel

func (edge LPGEdge) SetLabel(label string)

func (LPGEdge) SetProperties

func (edge LPGEdge) SetProperties(properties map[string]Value)

func (LPGEdge) SetProperty

func (edge LPGEdge) SetProperty(name string, value Value)

func (LPGEdge) To

func (edge LPGEdge) To() Node

type LPGGraph

type LPGGraph struct {
	Graph *lpg.Graph
}

func NewLPGGraph

func NewLPGGraph(g *lpg.Graph) LPGGraph

func (LPGGraph) DeleteEdge

func (g LPGGraph) DeleteEdge(edge Edge) error

func (LPGGraph) DetachDeleteNode

func (g LPGGraph) DetachDeleteNode(node Node) error

func (LPGGraph) NewEdge

func (g LPGGraph) NewEdge(from, to Node, label string, properties map[string]Value) (Edge, error)

func (LPGGraph) NewNode

func (g LPGGraph) NewNode(labels []string, properties map[string]Value) (Node, error)

func (LPGGraph) SearchPattern

func (g LPGGraph) SearchPattern(ctx *EvalContext, crit PathCriteria) (GraphCursor, error)

type LPGGraphCursor

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

func (*LPGGraphCursor) Close

func (cursor *LPGGraphCursor) Close()

func (*LPGGraphCursor) Err

func (cursor *LPGGraphCursor) Err() error

func (*LPGGraphCursor) Next

func (cursor *LPGGraphCursor) Next() bool

func (*LPGGraphCursor) Path

func (cursor *LPGGraphCursor) Path() Path

func (*LPGGraphCursor) SymbolValue

func (cursor *LPGGraphCursor) SymbolValue(sym string) Value

Return the value of the symbol in the current element

type LPGNode

type LPGNode struct {
	Node *lpg.Node
}

func (LPGNode) GetProperties

func (node LPGNode) GetProperties() map[string]Value

func (LPGNode) GetProperty

func (node LPGNode) GetProperty(name string) Value

func (LPGNode) HasIncomingEdges

func (node LPGNode) HasIncomingEdges() bool

func (LPGNode) HasLabel

func (node LPGNode) HasLabel(label string) bool

func (LPGNode) HasOutgoingEdges

func (node LPGNode) HasOutgoingEdges() bool

func (LPGNode) ID

func (node LPGNode) ID() any

func (LPGNode) Labels

func (node LPGNode) Labels() []string

func (LPGNode) Native

func (node LPGNode) Native() any

func (LPGNode) RemoveProperty

func (node LPGNode) RemoveProperty(name string)

func (LPGNode) SetLabels

func (node LPGNode) SetLabels(labels []string)

func (LPGNode) SetProperties

func (node LPGNode) SetProperties(properties map[string]Value)

func (LPGNode) SetProperty

func (node LPGNode) SetProperty(name string, value Value)

type LValue

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

LValue is a pointer to a value

func NewLValue

func NewLValue(v Value) LValue

NewLValue returns an LValue from the given value

func (LValue) Const

func (LValue) Const() bool

func (LValue) Constraints

func (expr LValue) Constraints(ctx *EvalContext) Constraint

func (LValue) Evaluate

func (v LValue) Evaluate(*EvalContext) (Value, error)

func (LValue) Get

func (v LValue) Get() any

func (LValue) Set

func (v LValue) Set(val any)

func (LValue) Tree

func (v LValue) Tree() any

func (LValue) Type

func (v LValue) Type() ValueType

type ListComprehensionExpression

type ListComprehensionExpression struct {
	Filter *FilterExpression
	Expr   Expression
}

func (*ListComprehensionExpression) Constraints

func (expr *ListComprehensionExpression) Constraints(ctx *EvalContext) Constraint

func (*ListComprehensionExpression) Evaluate

func (expr *ListComprehensionExpression) Evaluate(ctx *EvalContext) (Value, error)

func (ListComprehensionExpression) Tree

func (expr ListComprehensionExpression) Tree() any

func (ListComprehensionExpression) Type

type ListLiteral

type ListLiteral struct {
	Values []Expression

	Const Value
}

func (*ListLiteral) Constraints

func (expr *ListLiteral) Constraints(ctx *EvalContext) Constraint

func (*ListLiteral) Evaluate

func (expr *ListLiteral) Evaluate(ctx *EvalContext) (Value, error)

func (ListLiteral) Tree

func (l ListLiteral) Tree() any

func (ListLiteral) Type

func (ListLiteral) Type() ValueType

type LocalDateTime

type LocalDateTime time.Time // Date and time in local timezone

func NewLocalDateTime

func NewLocalDateTime(t time.Time) LocalDateTime

NewLocalDateTime creates a LocalDateTime from time.Time.

func (LocalDateTime) String

func (t LocalDateTime) String() string

func (LocalDateTime) Time

func (t LocalDateTime) Time() time.Time

Time casts LocalDateTime to time.Time

type LocalTime

type LocalTime time.Time // Time since start of day in local timezone

func NewLocalTime

func NewLocalTime(t time.Time) LocalTime

NewLocalTime creates a LocalTime from time.Time. Year, month and day are set to zero and location is set to local.

func (LocalTime) String

func (t LocalTime) String() string

func (LocalTime) Time

func (t LocalTime) Time() time.Time

Time casts LocalTime to time.Time

type MapLiteral

type MapLiteral struct {
	Val   map[string]Expression
	Const Value
}

func (*MapLiteral) Constraints

func (expr *MapLiteral) Constraints(ctx *EvalContext) Constraint

func (*MapLiteral) Evaluate

func (expr *MapLiteral) Evaluate(ctx *EvalContext) (Value, error)

func (MapLiteral) Tree

func (l MapLiteral) Tree() any

func (MapLiteral) Type

func (MapLiteral) Type() ValueType

type Match

type Match struct {
	Optional bool
	Pattern  Pattern
	Where    Expression
}

func OC_Match

func OC_Match(ctx *parser.OC_MatchContext) (ret *Match, err error)

oC_Match:

( OPTIONAL SP )? MATCH SP? oC_Pattern ( SP? oC_Where )? ;

func (*Match) GetCursor

func (match *Match) GetCursor(ctx *EvalContext) (Cursor, error)

func (Match) IsOptional

func (m Match) IsOptional() bool

func (Match) Tree

func (m Match) Tree() any

type MergeAction

type MergeAction struct {
	On  MergeActionOn
	Set UpdatingClause
}

type MergeActionOn

type MergeActionOn int
const (
	MergeActionOnMatch MergeActionOn = iota
	MergeActionOnCreate
)

func (MergeActionOn) String

func (m MergeActionOn) String() string

type MergeClause

type MergeClause struct {
	Pattern PatternPart
	Actions []MergeAction
}

func (MergeClause) Tree

func (m MergeClause) Tree() any

func (*MergeClause) Update

func (merge *MergeClause) Update(ctx *EvalContext, input Cursor) (Cursor, error)

type MultiplicativeOperator

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

type MultiplyDivideModuloExpression

type MultiplyDivideModuloExpression struct {
	Expr       []Expression
	Op         []MultiplicativeOperator
	ResultType ValueType
}

func (*MultiplyDivideModuloExpression) Constraints

func (expr *MultiplyDivideModuloExpression) Constraints(ctx *EvalContext) Constraint

func (*MultiplyDivideModuloExpression) Evaluate

func (expr *MultiplyDivideModuloExpression) Evaluate(ctx *EvalContext) (Value, error)

func (MultiplyDivideModuloExpression) Tree

func (expr MultiplyDivideModuloExpression) Tree() any

func (MultiplyDivideModuloExpression) Type

type Node

type Node interface {
	ID() any
	HasLabel(string) bool
	Labels() []string
	SetLabels([]string)

	GetProperty(string) Value
	SetProperty(string, Value)
	RemoveProperty(string)
	SetProperties(map[string]Value)
	GetProperties() map[string]Value

	HasIncomingEdges() bool
	HasOutgoingEdges() bool

	Native() any
}

type NodeCriteria

type NodeCriteria struct {
	Name string

	Node Node
	// The nodes must have all these labels
	MustHaveLabels []string
	// The nodes must have at least one of these labels
	AtLeastOneLabel []string

	// Criteria for the properties
	Properties map[string]PropertyCriteria
}

type NodeLabelsConstraint

type NodeLabelsConstraint struct {
	Var    string
	Labels []string
}

func (NodeLabelsConstraint) BuildFilter

func (c NodeLabelsConstraint) BuildFilter(varName string) map[string]PropertyCriteria

func (NodeLabelsConstraint) CanInvert

func (NodeLabelsConstraint) CanInvert() bool

func (NodeLabelsConstraint) Invert

type NodePattern

type NodePattern struct {
	VariableName string
	Labels       []string
	Properties   *Properties
}

func OC_NodePattern

func OC_NodePattern(ctx *parser.OC_NodePatternContext) (ret NodePattern, err error)

oC_NodePattern:

'(' SP? ( oC_Variable SP? )? ( oC_NodeLabels SP? )? ( oC_Properties SP? )? ')' ;

func (NodePattern) GetNodeCriteria

func (node NodePattern) GetNodeCriteria(ctx *EvalContext) (NodeCriteria, error)

func (NodePattern) Tree

func (node NodePattern) Tree() any

type NontrivialConstraint

type NontrivialConstraint struct{}

func (NontrivialConstraint) BuildFilter

func (NontrivialConstraint) BuildFilter(varName string) map[string]PropertyCriteria

func (NontrivialConstraint) CanInvert

func (NontrivialConstraint) CanInvert() bool

func (NontrivialConstraint) Invert

type NotExpression

type NotExpression struct {
	Part Expression
}

func (*NotExpression) Constraints

func (expr *NotExpression) Constraints(ctx *EvalContext) Constraint

func (*NotExpression) Evaluate

func (expr *NotExpression) Evaluate(ctx *EvalContext) (Value, error)

func (NotExpression) Tree

func (expr NotExpression) Tree() any

func (NotExpression) Type

func (NotExpression) Type() ValueType

type NullCheckConstraint

type NullCheckConstraint struct {
	Var    VarConstraint
	IsNull bool
}

func (NullCheckConstraint) BuildFilter

func (c NullCheckConstraint) BuildFilter(varName string) map[string]PropertyCriteria

func (NullCheckConstraint) CanInvert

func (NullCheckConstraint) CanInvert() bool

func (NullCheckConstraint) Invert

func (c NullCheckConstraint) Invert() Constraint

type NullCheckExpression

type NullCheckExpression struct {
	Left        Expression
	CheckIsNull bool
}

func (*NullCheckExpression) Constraints

func (expr *NullCheckExpression) Constraints(ctx *EvalContext) Constraint

func (*NullCheckExpression) Evaluate

func (expr *NullCheckExpression) Evaluate(ctx *EvalContext) (Value, error)

func (NullCheckExpression) Tree

func (expr NullCheckExpression) Tree() any

func (NullCheckExpression) Type

type OrExpression

type OrExpression struct {
	Parts []Expression
}

func (*OrExpression) Constraints

func (expr *OrExpression) Constraints(ctx *EvalContext) Constraint

func (*OrExpression) Evaluate

func (expr *OrExpression) Evaluate(ctx *EvalContext) (Value, error)

func (OrExpression) Tree

func (expr OrExpression) Tree() any

func (OrExpression) Type

func (OrExpression) Type() ValueType

type Parameter

type Parameter struct {
	Name string
}

func (*Parameter) Constraints

func (expr *Parameter) Constraints(ctx *EvalContext) Constraint

func (*Parameter) Evaluate

func (expr *Parameter) Evaluate(ctx *EvalContext) (Value, error)

func (Parameter) Tree

func (expr Parameter) Tree() any

func (Parameter) Type

func (Parameter) Type() ValueType

type Path

type Path struct {
	Nodes []Node
	Edges []Edge
}

func (*Path) Equal

func (path *Path) Equal(p *Path) bool

type PathCriteria

type PathCriteria struct {
	Nodes []NodeCriteria
	Edges []EdgeCriteria
}

type PathPattern

type PathPattern struct {
	Nodes []NodePattern
	Rels  []RelationshipPattern
}

func OC_RelationshipsPattern

func OC_RelationshipsPattern(ctx *parser.OC_RelationshipsPatternContext) (*PathPattern, error)

oC_RelationshipsPattern : oC_NodePattern ( SP? oC_PatternElementChain )+ ; oC_PatternElementChain : oC_RelationshipPattern SP? oC_NodePattern ;

func (*PathPattern) Constraints

func (expr *PathPattern) Constraints(*EvalContext) Constraint

func (*PathPattern) Evaluate

func (expr *PathPattern) Evaluate(*EvalContext) (Value, error)

func (PathPattern) GetFreeVariables

func (p PathPattern) GetFreeVariables(ctx *EvalContext, offset int) []CursorColumn

Returns the free variables in the order they are defined. A free variable is one that is not defined in the context. The result set colum indexes start from the given offset

func (PathPattern) Tree

func (p PathPattern) Tree() any

func (PathPattern) Type

func (PathPattern) Type() ValueType

type Pattern

type Pattern struct {
	JoinParts []PatternPart
}

func OC_Pattern

func OC_Pattern(ctx *parser.OC_PatternContext) (Pattern, error)

oC_Pattern:

oC_PatternPart ( SP? ',' SP? oC_PatternPart )* ;

func (Pattern) Tree

func (p Pattern) Tree() any

type PatternComprehension

type PatternComprehension struct {
	Variable string
	Rel      *PathPattern
	Where    Expression
	Expr     Expression
}

func OC_PatternComprehension

func OC_PatternComprehension(ctx *parser.OC_PatternComprehensionContext) (*PatternComprehension, error)

oC_PatternComprehension:

'[' SP? ( oC_Variable SP? '=' SP? )? oC_RelationshipsPattern SP? ( WHERE SP? oC_Expression SP? )? '|' SP? oC_Expression SP? ']'

func (*PatternComprehension) Constraints

func (*PatternComprehension) Evaluate

func (PatternComprehension) Tree

func (expr PatternComprehension) Tree() any

func (PatternComprehension) Type

type PatternPart

type PatternPart struct {
	VariableName string
	Path         PathPattern
}

func OC_PatternPart

func OC_PatternPart(ctx *parser.OC_PatternPartContext) (ret PatternPart, err error)

oC_PatternPart:

( oC_Variable SP? '=' SP? oC_AnonymousPatternPart ) | oC_AnonymousPatternPart

func (PatternPart) Tree

func (p PatternPart) Tree() any

type PowerOfExpression

type PowerOfExpression struct {
	Expr []Expression
}

func (*PowerOfExpression) Constraints

func (expr *PowerOfExpression) Constraints(ctx *EvalContext) Constraint

func (*PowerOfExpression) Evaluate

func (expr *PowerOfExpression) Evaluate(ctx *EvalContext) (Value, error)

func (PowerOfExpression) Tree

func (expr PowerOfExpression) Tree() any

func (PowerOfExpression) Type

func (expr PowerOfExpression) Type() ValueType

type Procedure

type Procedure struct {
	Name    string
	MinArgs int
	MaxArgs int
	Cols    []CursorColumn
	Proc    func(*EvalContext, []Expression) (Cursor, error)
}

Procedure describes a global procedure

type ProcedureCall

type ProcedureCall struct {
	Proc  *ProcedureInvocation
	Yield *YieldItems
}

func OC_InQueryCall

func OC_InQueryCall(ctx *parser.OC_InQueryCallContext) (*ProcedureCall, error)

oC_InQueryCall:

CALL SP oC_ExplicitProcedureInvocation ( SP? YIELD SP oC_YieldItems )? ;

func OC_StandaloneCall

func OC_StandaloneCall(ctx *parser.OC_StandaloneCallContext) (*ProcedureCall, error)

oC_StandaloneCall:

CALL SP ( oC_ExplicitProcedureInvocation | oC_ImplicitProcedureInvocation ) ( SP YIELD SP oC_YieldItems )? ;

func (*ProcedureCall) GetCursor

func (call *ProcedureCall) GetCursor(ctx *EvalContext) (Cursor, error)

func (ProcedureCall) IsOptional

func (ProcedureCall) IsOptional() bool

func (ProcedureCall) Tree

func (c ProcedureCall) Tree() any

type ProcedureInvocation

type ProcedureInvocation struct {
	Namespace string
	Name      string
	Args      []Expression
}

func OC_ExplicitProcedureInvocation

func OC_ExplicitProcedureInvocation(ctx *parser.OC_ExplicitProcedureInvocationContext) (*ProcedureInvocation, error)

oC_ExplicitProcedureInvocation:

oC_ProcedureName SP? '(' SP? ( oC_Expression SP? ( ',' SP? oC_Expression SP? )* )? ')' ;

func OC_ImplicitProcedureInvocation

func OC_ImplicitProcedureInvocation(ctx *parser.OC_ImplicitProcedureInvocationContext) (*ProcedureInvocation, error)

oC_ImplicitProcedureInvocation: oC_ProcedureName

func (ProcedureInvocation) Tree

func (p ProcedureInvocation) Tree() any

type ProjectionBody

type ProjectionBody struct {
	Distinct bool
	Items    []ProjectionItem
	Order    []SortItem
	Skip     Expression
	Limit    Expression
}

func OC_ProjectionBody

func OC_ProjectionBody(ctx *parser.OC_ProjectionBodyContext) (*ProjectionBody, error)

oC_ProjectionBody:

( SP? DISTINCT )? SP oC_ProjectionItems ( SP oC_Order )? ( SP oC_Skip )? ( SP oC_Limit )? ;

func (*ProjectionBody) Project

func (prj *ProjectionBody) Project(ctx *EvalContext, rs Cursor) (Cursor, error)

func (ProjectionBody) Tree

func (p ProjectionBody) Tree() any

type ProjectionItem

type ProjectionItem struct {
	All   bool
	Alias string
	Expr  Expression
}

func OC_ProjectionItem

func OC_ProjectionItem(ctx *parser.OC_ProjectionItemContext) (item ProjectionItem, err error)

oC_ProjectionItem:

( oC_Expression SP AS SP oC_Variable )| oC_Expression

func OC_ProjectionItems

func OC_ProjectionItems(ctx *parser.OC_ProjectionItemsContext) ([]ProjectionItem, error)

oC_ProjectionItems:

( '*' ( SP? ',' SP? oC_ProjectionItem )* ) | ( oC_ProjectionItem ( SP? ',' SP? oC_ProjectionItem )* )

func (ProjectionItem) Tree

func (p ProjectionItem) Tree() any

type Properties

type Properties struct {
	Lit   *MapLiteral
	Param *Parameter
}

func OC_Properties

func OC_Properties(ctx *parser.OC_PropertiesContext) (Properties, error)

oC_Properties : oC_MapLiteral | oC_Parameter

func (*Properties) Evaluate

func (expr *Properties) Evaluate(ctx *EvalContext) (Value, error)

func (Properties) Tree

func (p Properties) Tree() any

type PropertyCriteria

type PropertyCriteria struct {
	PropertyName string
	// Property value is equal to one of the given values
	OneOf []Value

	// Property value has the given prefix/suffix or substring
	StringValue string
	StringOp    StringOperator

	// Value ranges
	Ranges []PropertyValueRange
}

PropertyCriteria values are ORed. For instance, if there is one of values and a prefix, all values that have that prefix and oneof values will match

type PropertyExpression

type PropertyExpression struct {
	Atom     Expression
	Property []string
}

PropertyExpression represents an expression of the form: (value).property1.property2... This is used in update expressions

func (*PropertyExpression) Constraints

func (expr *PropertyExpression) Constraints(ctx *EvalContext) Constraint

func (*PropertyExpression) Evaluate

func (expr *PropertyExpression) Evaluate(ctx *EvalContext) (Value, error)

func (PropertyExpression) Tree

func (expr PropertyExpression) Tree() any

func (PropertyExpression) Type

type PropertyOrLabelsExpression

type PropertyOrLabelsExpression struct {
	Atom       Expression
	Properties []string
	NodeLabels []string
}

func (*PropertyOrLabelsExpression) Constraints

func (expr *PropertyOrLabelsExpression) Constraints(ctx *EvalContext) Constraint

func (*PropertyOrLabelsExpression) Evaluate

func (expr *PropertyOrLabelsExpression) Evaluate(ctx *EvalContext) (Value, error)

func (PropertyOrLabelsExpression) Tree

func (expr PropertyOrLabelsExpression) Tree() any

func (PropertyOrLabelsExpression) Type

type PropertyValueRange

type PropertyValueRange struct {
	MinExclusive Value
	MinInclusive Value
	MaxExclusive Value
	MaxInclusive Value
}

type Query

type Query interface {
	GetCursor(*EvalContext) (Cursor, error)
	Tree() any
	// contains filtered or unexported methods
}

A query is a clause that produces a resultset

func OC_Cypher

func OC_Cypher(ctx *parser.OC_CypherContext) (Query, error)

oC_Cypher : SP? oC_Statement ( SP? ';' )? SP? EOF ;

func OC_Query

func OC_Query(ctx *parser.OC_QueryContext) (Query, error)

oC_Query : oC_RegularQuery | oC_StandaloneCall;

func OC_RegularQuery

func OC_RegularQuery(ctx *parser.OC_RegularQueryContext) (Query, error)

oC_RegularQuery : oC_SingleQuery ( SP? oC_Union )* ; oC_Union : ( UNION SP ALL SP? oC_SingleQuery ) | ( UNION SP? oC_SingleQuery ) ;

func OC_Statement

func OC_Statement(ctx *parser.OC_StatementContext) (Query, error)

oC_Statement : oC_Query ;

func Parse

func Parse(input string) (Query, error)

Parse returns a parsed Query

type RValue

type RValue struct {
	Value    any
	Constant bool
	Typ      ValueType
}

RValue is a value

func (RValue) Const

func (v RValue) Const() bool

func (RValue) Constraints

func (expr RValue) Constraints(ctx *EvalContext) Constraint

func (RValue) Evaluate

func (v RValue) Evaluate(*EvalContext) (Value, error)

func (RValue) Get

func (v RValue) Get() any

func (RValue) Tree

func (v RValue) Tree() any

func (RValue) Type

func (v RValue) Type() ValueType

type RangeLiteral

type RangeLiteral struct {
	From *int
	To   *int
}

func OC_RangeLiteral

func OC_RangeLiteral(ctx *parser.OC_RangeLiteralContext) (RangeLiteral, error)

oC_RangeLiteral : '*' SP? ( oC_IntegerLiteral SP? )? ( '..' SP? ( oC_IntegerLiteral SP? )? )? ;

func (RangeLiteral) Tree

func (r RangeLiteral) Tree() any

type ReadingClause

type ReadingClause interface {
	GetCursor(*EvalContext) (Cursor, error)
	IsOptional() bool
	Tree() any
	// contains filtered or unexported methods
}

func OC_ReadingClause

func OC_ReadingClause(ctx *parser.OC_ReadingClauseContext) (ReadingClause, error)

oC_ReadingClause : oC_Match | oC_Unwind | oC_InQueryCall ;

type RelationalConstraint

type RelationalConstraint struct {
	Var   VarConstraint
	Op    string
	Value Value
}

func (RelationalConstraint) BuildFilter

func (c RelationalConstraint) BuildFilter(varName string) map[string]PropertyCriteria

func (RelationalConstraint) CanInvert

func (RelationalConstraint) CanInvert() bool

func (RelationalConstraint) Invert

func (c RelationalConstraint) Invert() Constraint

type RelationshipPattern

type RelationshipPattern struct {
	ToLeft       bool
	ToRight      bool
	VariableName string
	RelTypes     []string
	Range        *RangeLiteral
	Properties   *Properties
}

func OC_RelationshipPattern

func OC_RelationshipPattern(ctx *parser.OC_RelationshipPatternContext) (ret RelationshipPattern, err error)

oC_RelationshipPattern:

( oC_LeftArrowHead SP? oC_Dash SP? oC_RelationshipDetail? SP? oC_Dash SP? oC_RightArrowHead ) | ( oC_LeftArrowHead SP? oC_Dash SP? oC_RelationshipDetail? SP? oC_Dash ) | ( oC_Dash SP? oC_RelationshipDetail? SP? oC_Dash SP? oC_RightArrowHead ) | ( oC_Dash SP? oC_RelationshipDetail? SP? oC_Dash )

func (RelationshipPattern) Tree

func (rel RelationshipPattern) Tree() any

type RemoveClause

type RemoveClause struct {
	Items []RemoveItem
}

func (RemoveClause) Tree

func (r RemoveClause) Tree() any

func (*RemoveClause) Update

func (rm *RemoveClause) Update(ctx *EvalContext, input Cursor) (Cursor, error)

type RemoveItem

type RemoveItem struct {
	Variable   *VariableAccessExpression
	NodeLabels []string
	Property   *PropertyExpression
}

func OC_RemoveItem

func OC_RemoveItem(ctx *parser.OC_RemoveItemContext) (RemoveItem, error)

oC_RemoveItem :

( oC_Variable oC_NodeLabels )
  | oC_PropertyExpression

func (RemoveItem) DeleteLabel

func (r RemoveItem) DeleteLabel(l string) bool

Returns if the label is to be deleted

func (RemoveItem) Tree

func (r RemoveItem) Tree() any

type Return

type Return struct {
	Projection *ProjectionBody
}

func OC_Return

func OC_Return(ctx *parser.OC_ReturnContext) (*Return, error)

func (Return) Tree

func (r Return) Tree() any

type SetClause

type SetClause struct {
	Items []SetItem
}

func (SetClause) Tree

func (s SetClause) Tree() any

func (*SetClause) Update

func (set *SetClause) Update(ctx *EvalContext, input Cursor) (Cursor, error)

type SetItem

type SetItem struct {
	Property   *PropertyExpression
	Variable   *VariableAccessExpression
	Op         string
	Expression Expression
	NodeLabels []string
}

func OC_SetItem

func OC_SetItem(ctx *parser.OC_SetItemContext) (SetItem, error)

oC_SetItem:

( oC_PropertyExpression SP? '=' SP? oC_Expression )
  | ( oC_Variable SP? '=' SP? oC_Expression )
  | ( oC_Variable SP? '+=' SP? oC_Expression )
  | ( oC_Variable SP? oC_NodeLabels )
  ;

func (SetItem) Tree

func (s SetItem) Tree() any

type SingleQuery

type SingleQuery struct {
	Stages []SingleQueryStage
	Ret    *Return
	// contains filtered or unexported fields
}

A single query contains a pipeline of (read-update-with) constructs, and then a projection

func OC_MultiPartQuery

func OC_MultiPartQuery(ctx *parser.OC_MultiPartQueryContext) (*SingleQuery, error)

oC_MultiPartQuery

:  ( ( oC_ReadingClause SP? )* ( oC_UpdatingClause SP? )* oC_With SP? )+ oC_SinglePartQuery ;

func OC_SinglePartQuery

func OC_SinglePartQuery(ctx *parser.OC_SinglePartQueryContext) (*SingleQuery, error)

oC_SinglePartQuery :

  ( ( oC_ReadingClause SP? )* oC_Return ) |

	( ( oC_ReadingClause SP? )* oC_UpdatingClause ( SP? oC_UpdatingClause )* ( SP? oC_Return )? )

func OC_SingleQuery

func OC_SingleQuery(ctx *parser.OC_SingleQueryContext) (ret *SingleQuery, err error)

oC_SingleQuery : oC_SinglePartQuery | oC_MultiPartQuery ;

func (*SingleQuery) GetCursor

func (query *SingleQuery) GetCursor(ctx *EvalContext) (Cursor, error)

func (*SingleQuery) IsOptional

func (*SingleQuery) IsOptional() bool

func (SingleQuery) Tree

func (u SingleQuery) Tree() any

type SingleQueryStage

type SingleQueryStage struct {
	Read   []ReadingClause
	Update []UpdatingClause
	With   *With
}

type SortDirection

type SortDirection int
const (
	SortAscending SortDirection = iota
	SortDescending
)

func (SortDirection) String

func (s SortDirection) String() string

type SortItem

type SortItem struct {
	Dir  SortDirection
	Expr Expression
}

func OC_Order

func OC_Order(ctx *parser.OC_OrderContext) ([]SortItem, error)

oC_Order:

ORDER SP BY SP oC_SortItem ( ',' SP? oC_SortItem )*

func OC_SortItem

func OC_SortItem(ctx *parser.OC_SortItemContext) (ret SortItem, err error)

oC_SortItem:

oC_Expression ( SP? ( ASCENDING | ASC | DESCENDING | DESC ) )? ;

func (SortItem) Tree

func (s SortItem) Tree() any

type StringConstraint

type StringConstraint struct {
	Var   VarConstraint
	Op    StringOperator
	Value string
}

func (StringConstraint) BuildFilter

func (c StringConstraint) BuildFilter(varName string) map[string]PropertyCriteria

func (StringConstraint) CanInvert

func (StringConstraint) CanInvert() bool

func (StringConstraint) Invert

func (StringConstraint) Invert() Constraint

type StringOperator

type StringOperator int
const (
	StringOperatorStartsWith StringOperator = iota
	StringOperatorEndsWith
	StringOperatorContains
)

func (StringOperator) String

func (s StringOperator) String() string

type StringOperatorExpression

type StringOperatorExpression struct {
	Left  Expression
	Op    StringOperator
	Right Expression
}

func (*StringOperatorExpression) Constraints

func (expr *StringOperatorExpression) Constraints(ctx *EvalContext) Constraint

func (*StringOperatorExpression) Evaluate

func (expr *StringOperatorExpression) Evaluate(ctx *EvalContext) (Value, error)

func (StringOperatorExpression) Tree

func (expr StringOperatorExpression) Tree() any

func (StringOperatorExpression) Type

type SublistExpression

type SublistExpression struct {
	Left Expression
	From Expression
	To   Expression
}

func (*SublistExpression) Constraints

func (expr *SublistExpression) Constraints(ctx *EvalContext) Constraint

func (*SublistExpression) Evaluate

func (expr *SublistExpression) Evaluate(ctx *EvalContext) (Value, error)

func (SublistExpression) Tree

func (expr SublistExpression) Tree() any

func (SublistExpression) Type

type Time

type Time time.Time // Time since start of day with timezone information

func (Time) String

func (t Time) String() string

func (Time) Time

func (t Time) Time() time.Time

Time casts Time to time.Time

type UnarySubtractExpression

type UnarySubtractExpression struct {
	Expr Expression
}

func (*UnarySubtractExpression) Constraints

func (expr *UnarySubtractExpression) Constraints(ctx *EvalContext) Constraint

func (*UnarySubtractExpression) Evaluate

func (expr *UnarySubtractExpression) Evaluate(ctx *EvalContext) (Value, error)

func (UnarySubtractExpression) Tree

func (expr UnarySubtractExpression) Tree() any

func (UnarySubtractExpression) Type

func (expr UnarySubtractExpression) Type() ValueType

type Union

type Union struct {
	Stages []UnionStage
}

Computes the union of the resultsets of a sequence of queries

func (*Union) GetCursor

func (query *Union) GetCursor(ctx *EvalContext) (Cursor, error)

func (Union) Tree

func (u Union) Tree() any

type UnionStage

type UnionStage struct {
	IncludeAll bool
	Query      *SingleQuery
}

type Unwind

type Unwind struct {
	Expr Expression
	As   string
}

func OC_Unwind

func OC_Unwind(ctx *parser.OC_UnwindContext) (*Unwind, error)

func (*Unwind) GetCursor

func (unwind *Unwind) GetCursor(ctx *EvalContext) (Cursor, error)

func (Unwind) IsOptional

func (Unwind) IsOptional() bool

func (Unwind) Tree

func (u Unwind) Tree() any

type UpdatingClause

type UpdatingClause interface {
	Update(ctx *EvalContext, input Cursor) (Cursor, error)
	Tree() any
	// contains filtered or unexported methods
}

func OC_Create

func OC_Create(ctx *parser.OC_CreateContext) (UpdatingClause, error)

oC_Create : CREATE SP? oC_Pattern ;

func OC_Delete

func OC_Delete(ctx *parser.OC_DeleteContext) (UpdatingClause, error)

oC_Delete : ( DETACH SP )? DELETE SP? oC_Expression ( SP? ',' SP? oC_Expression )* ;

func OC_Merge

func OC_Merge(ctx *parser.OC_MergeContext) (UpdatingClause, error)

oC_Merge: MERGE SP? oC_PatternPart ( SP oC_MergeAction )* ;

func OC_Remove

func OC_Remove(ctx *parser.OC_RemoveContext) (UpdatingClause, error)

oC_Remove : REMOVE SP oC_RemoveItem ( SP? ',' SP? oC_RemoveItem )* ;

func OC_Set

func OC_Set(ctx *parser.OC_SetContext) (UpdatingClause, error)

oC_Set: SET SP? oC_SetItem ( SP? ',' SP? oC_SetItem )* ;

func OC_UpdatingClause

func OC_UpdatingClause(ctx *parser.OC_UpdatingClauseContext) (UpdatingClause, error)

oC_UpdatingClause : oC_Create | oC_Merge | oC_Delete | oC_Set | oC_Remove ;

type Value

type Value interface {
	Expression
	Get() any
	Const() bool
}

func GetNamedColumn

func GetNamedColumn(rs Cursor, name string) Value

GetNamedColumn returns a column from the current row by name

func ValueOf

func ValueOf(in any) Value

type ValueConstraint

type ValueConstraint struct {
	Value Value
}

func (ValueConstraint) BuildFilter

func (c ValueConstraint) BuildFilter(varName string) map[string]PropertyCriteria

func (ValueConstraint) CanInvert

func (ValueConstraint) CanInvert() bool

func (ValueConstraint) Invert

func (ValueConstraint) Invert() Constraint

type ValueType

type ValueType int
const (
	AnyType ValueType = iota
	IntType
	FloatType
	BoolType
	StringType
	DurationType
	DateType
	LocalDateTimeType
	LocalTimeType
	NodeType
	EdgeType
	PathType
	ListType
	ObjectType
)

func (ValueType) String

func (v ValueType) String() string

type VarConstraint

type VarConstraint struct {
	Name       string
	Properties []string
}

func (VarConstraint) BuildFilter

func (c VarConstraint) BuildFilter(varName string) map[string]PropertyCriteria

func (VarConstraint) CanInvert

func (VarConstraint) CanInvert() bool

func (VarConstraint) Invert

func (VarConstraint) Invert() Constraint

type VariableAccessExpression

type VariableAccessExpression struct {
	Name string
}

func (*VariableAccessExpression) Constraints

func (expr *VariableAccessExpression) Constraints(ctx *EvalContext) Constraint

func (*VariableAccessExpression) Evaluate

func (expr *VariableAccessExpression) Evaluate(ctx *EvalContext) (Value, error)

func (VariableAccessExpression) Tree

func (expr VariableAccessExpression) Tree() any

func (VariableAccessExpression) Type

type With

type With struct {
	Projection *ProjectionBody
	Where      Expression
}

func OC_With

func OC_With(ctx *parser.OC_WithContext) (*With, error)

func (With) Tree

func (w With) Tree() any

type XorExpression

type XorExpression struct {
	Parts []Expression
}

func (*XorExpression) Constraints

func (expr *XorExpression) Constraints(ctx *EvalContext) Constraint

func (*XorExpression) Evaluate

func (expr *XorExpression) Evaluate(ctx *EvalContext) (Value, error)

func (XorExpression) Tree

func (expr XorExpression) Tree() any

func (XorExpression) Type

func (XorExpression) Type() ValueType

type YieldItem

type YieldItem struct {
	ResultField string
	AsVariable  string
}

func OC_YieldItem

func OC_YieldItem(ctx *parser.OC_YieldItemContext) YieldItem

oC_YieldItem:

( oC_ProcedureResultField SP AS SP )? oC_Variable ;

type YieldItems

type YieldItems struct {
	All   bool
	Items []YieldItem
	Where Expression
}

func OC_YieldItems

func OC_YieldItems(ctx *parser.OC_YieldItemsContext) (*YieldItems, error)

oC_YieldItems:

( '*' | ( oC_YieldItem ( SP? ',' SP? oC_YieldItem )* ) ) ( SP? oC_Where )? ;

func (YieldItems) Tree

func (y YieldItems) Tree() any

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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