Help us shape the future of Go! Take the 2026 Go Developer Survey

opencypher

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package opencypher is an in-process openCypher engine over an in-memory property graph.

Supported: MATCH, OPTIONAL MATCH, WHERE, CREATE, MERGE (ON CREATE/ON MATCH SET), SET, REMOVE, DELETE, DETACH DELETE, WITH, UNWIND, RETURN with DISTINCT, ORDER BY, SKIP, LIMIT, parameters, variable-length relationships, CASE, list/map expressions, the common scalar functions and the count, collect, sum, avg, min and max aggregates. Not supported: CALL, UNION, FOREACH, LOAD CSV, pattern predicates in WHERE, list comprehensions, shortestPath, constraints and indexes.

Index

Constants

View Source
const (
	CodeMalformedQuery      = "MalformedQueryException"
	CodeUnsupported         = "UnsupportedOperationException"
	CodeConstraintViolation = "ConstraintViolationException"
	CodeInvalidParameter    = "InvalidParameterException"
)

Error codes match the Neptune openCypher HTTP API.

View Source
const IDProperty = "~id"

IDProperty is the property key that sets or reads an entity id.

Variables

This section is empty.

Functions

func Explain

func Explain(src, mode string) (string, error)

Explain renders the operator pipeline of src as Neptune's explain table (mode is static, dynamic or details).

func ParseParameters

func ParseParameters(raw string) (map[string]any, error)

ParseParameters decodes Neptune's `parameters` JSON object into engine values.

Types

type Error

type Error struct {
	Code   string
	Detail string
}

Error is a query failure carrying the Neptune error code.

func AsError

func AsError(err error) (*Error, bool)

AsError extracts an *Error from err.

func (*Error) Error

func (e *Error) Error() string

type Graph

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

Graph is a thread-safe in-memory property graph with an openCypher executor.

func NewGraph

func NewGraph() *Graph

NewGraph returns an empty graph.

func (*Graph) Begin

func (g *Graph) Begin(ctx context.Context) (*Tx, error)

Begin starts an explicit transaction, waiting for other users of the graph.

func (*Graph) Counts

func (g *Graph) Counts() (int, int)

Counts returns the number of nodes and relationships.

func (*Graph) Execute

func (g *Graph) Execute(ctx context.Context, src string, params map[string]any) (*Result, error)

Execute runs one openCypher query. Write queries are atomic: a failure leaves the graph unchanged.

func (*Graph) Export

func (g *Graph) Export(ctx context.Context) ([]byte, error)

Export serialises the graph to JSON, preserving integer/float distinctions.

func (*Graph) Import

func (g *Graph) Import(ctx context.Context, data []byte) error

Import replaces the graph contents with a dump produced by Export.

func (*Graph) Update

func (g *Graph) Update(ctx context.Context, fn func(*Store) error) error

Update runs fn with exclusive access; any error rolls every change back.

func (*Graph) View

func (g *Graph) View(ctx context.Context, fn func(*Store) error) error

View runs fn with exclusive access for reads only.

type Node

type Node struct {
	Props  map[string]any
	ID     string
	Labels []string
	// contains filtered or unexported fields
}

Node is a labelled vertex.

type Path

type Path struct {
	Nodes []*Node
	Rels  []*Rel
}

Path is an alternating node/relationship walk.

type Rel

type Rel struct {
	Props map[string]any
	ID    string
	Type  string
	Start string
	End   string
	// contains filtered or unexported fields
}

Rel is a directed, typed edge.

type Result

type Result struct {
	Columns []string
	Rows    [][]any
	Write   bool
}

Result is the table produced by RETURN; a query with no RETURN has no columns.

func (*Result) MarshalJSON

func (r *Result) MarshalJSON() ([]byte, error)

MarshalJSON renders the rows as Neptune's openCypher results array (entities use ~id/~entityType shapes).

type Store

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

Store is exclusive access to a graph's entities, handed to other query languages (Gremlin) so they share the same data, locking and rollback as openCypher.

func (*Store) AddNode

func (s *Store) AddNode(id string, labels []string, props map[string]any) (*Node, error)

AddNode creates a node; an empty id generates one.

func (*Store) AddRel

func (s *Store) AddRel(id, typ string, from, to *Node, props map[string]any) (*Rel, error)

AddRel creates a relationship; an empty id generates one.

func (*Store) DeleteNode

func (s *Store) DeleteNode(n *Node)

DeleteNode removes a node and its relationships.

func (*Store) DeleteRel

func (s *Store) DeleteRel(r *Rel)

DeleteRel removes a relationship.

func (*Store) InRels

func (s *Store) InRels(id string) []*Rel

InRels returns the relationships entering id.

func (*Store) Node

func (s *Store) Node(id string) *Node

Node returns the node with id, or nil.

func (*Store) Nodes

func (s *Store) Nodes() []*Node

Nodes returns every node in creation order.

func (*Store) OutRels

func (s *Store) OutRels(id string) []*Rel

OutRels returns the relationships leaving id.

func (*Store) Rel

func (s *Store) Rel(id string) *Rel

Rel returns the relationship with id, or nil.

func (*Store) Rels

func (s *Store) Rels() []*Rel

Rels returns every relationship in creation order.

type Tx

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

Tx is an explicit transaction holding the graph exclusively until Commit or Rollback.

func (*Tx) Commit

func (t *Tx) Commit()

Commit keeps the transaction's writes and releases the graph.

func (*Tx) Execute

func (t *Tx) Execute(ctx context.Context, src string, params map[string]any) (*Result, error)

Execute runs a query inside the transaction.

func (*Tx) Rollback

func (t *Tx) Rollback()

Rollback discards the transaction's writes and releases the graph.

Jump to

Keyboard shortcuts

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