gremlin

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gremlin provides Gremlin client, graph operation, and traversal helpers.

New code should construct clients from core-owned options and depend on graph contracts at the consumer boundary:

import "github.com/InsideGallery/core/db/gremlin"

client, err := gremlin.NewClient(gremlin.Options{URL: "ws://127.0.0.1:8182/gremlin"})

Prefer VertexStore or GraphStore with UpsertVertexOptions, UpsertEdgeOptions, CountVerticesOptions, ListValuesOptions, and their result types instead of exposing Gremlin SDK traversal values through application interfaces.

Compatibility: legacy traversal helpers and package-level syntax state remain available for existing consumers. Prefer explicit options and SyntaxState in new code.

Index

Constants

View Source
const (
	SyntaxAerospike   = "aerospike"
	SyntaxNeptun      = "neptun"
	DefaultPropertyID = "id"
)
View Source
const EnvPrefix = "GREMLIN"

EnvPrefix environment prefix for gremlin config

Variables

View Source
var (

	// PropertyID is the legacy package-level Gremlin property identifier.
	//
	// Deprecated: use NewSyntaxState and pass SyntaxState explicitly.
	PropertyID interface{} = DefaultPropertyID

	// Syntax is the legacy package-level Gremlin syntax selector.
	//
	// Deprecated: use NewSyntaxState and pass SyntaxState explicitly.
	Syntax = SyntaxAerospike
)
View Source
var ErrCastType = errors.New("error cast type")

Functions

func ApplySyntaxState deprecated added in v1.1.0

func ApplySyntaxState(state SyntaxState)

ApplySyntaxState updates the legacy package-level syntax state.

Deprecated: pass SyntaxState explicitly instead of mutating package-level state.

func ExecIterate

func ExecIterate(ch <-chan error) error

func GetConnection deprecated

func GetConnection(
	cfg *ConnectionConfig,
	configurations ...func(settings *gremlingo.DriverRemoteConnectionSettings),
) (*gremlingo.DriverRemoteConnection, error)

GetConnection creates the legacy Gremlin remote connection.

Deprecated: use NewClient for new code.

func InstallSyntaxState deprecated added in v1.1.0

func InstallSyntaxState(state SyntaxState) func()

InstallSyntaxState applies a legacy package-level syntax state with a restore path.

Deprecated: pass SyntaxState explicitly instead of mutating package-level state.

func MergeE

func MergeE(
	t *gremlingo.GraphTraversal,
	edge string,
	id string,
	vertex1, vertex2 *gremlingo.Vertex,
	properties map[interface{}]interface{},
) *gremlingo.GraphTraversal

func MergeV

func MergeV(
	t *gremlingo.GraphTraversal,
	label, id string,
	properties map[interface{}]interface{},
) *gremlingo.GraphTraversal

func PrepareProperties

func PrepareProperties(properties ...interface{}) map[interface{}]interface{}

func Setup added in v1.1.0

func Setup(state SyntaxState)

Setup applies a Gremlin syntax state to the legacy package-level globals.

func WrapCount

func WrapCount(t *gremlingo.GraphTraversal) (int64, error)

func WrapLabelFilter

func WrapLabelFilter(t *gremlingo.GraphTraversal, label string) *gremlingo.GraphTraversal

func WrapOrderAsc

func WrapOrderAsc(t *gremlingo.GraphTraversal, property string) *gremlingo.GraphTraversal

func WrapOrderDesc

func WrapOrderDesc(t *gremlingo.GraphTraversal, property string) *gremlingo.GraphTraversal

func WrapOrderGt

func WrapOrderGt(t *gremlingo.GraphTraversal, property string, value interface{}) *gremlingo.GraphTraversal

func WrapOrderGte

func WrapOrderGte(t *gremlingo.GraphTraversal, property string, value interface{}) *gremlingo.GraphTraversal

func WrapOrderLt

func WrapOrderLt(t *gremlingo.GraphTraversal, property string, value interface{}) *gremlingo.GraphTraversal

func WrapOrderLte

func WrapOrderLte(t *gremlingo.GraphTraversal, property string, value interface{}) *gremlingo.GraphTraversal

func WrapValuesToList

func WrapValuesToList(t *gremlingo.GraphTraversal, values string) ([]*gremlingo.Result, error)

Types

type Cache

type Cache struct {
	*registry.Registry[string, string, any]
	// contains filtered or unexported fields
}

func NewCache

func NewCache() *Cache

func (*Cache) AddVertex

func (c *Cache) AddVertex(label, id string, vertex *gremlingo.Vertex) error

func (*Cache) DeleteVertex

func (c *Cache) DeleteVertex(label, id string) error

func (*Cache) GetVertex

func (c *Cache) GetVertex(label, id string) (*gremlingo.Vertex, error)

func (*Cache) Truncate

func (c *Cache) Truncate()

type CallbackOp

type CallbackOp struct {
	*ResultOp
	// contains filtered or unexported fields
}

func NewCallbackOp

func NewCallbackOp(
	fn func(cache *Cache, source *gremlingo.GraphTraversalSource) ([]*gremlingo.Result, error),
) *CallbackOp

func (*CallbackOp) Execute

func (o *CallbackOp) Execute(cache *Cache, source *gremlingo.GraphTraversalSource) error

type Client deprecated

type Client struct {
	Connection *gremlingo.DriverRemoteConnection
}

Client is the legacy Gremlin SDK-shaped client.

Deprecated: use VertexStore and core-owned option/result types for new code.

func New

func New(
	cfg *ConnectionConfig,
	configurations ...func(settings *gremlingo.DriverRemoteConnectionSettings),
) (*Client, error)

func NewClient added in v1.1.0

func NewClient(options Options) (*Client, error)

NewClient creates a Gremlin client from core-owned options.

func (*Client) Close

func (c *Client) Close()

func (*Client) CloseGraph added in v1.1.0

func (c *Client) CloseGraph(ctx context.Context) error

CloseGraph closes the Gremlin client through the core-owned contract.

func (*Client) CountVertices added in v1.1.0

func (c *Client) CountVertices(ctx context.Context, options CountVerticesOptions) (CountResult, error)

CountVertices counts matching vertices without exposing traversal helper types.

func (*Client) Execute

func (c *Client) Execute(cache *Cache, ops ...Operation) error

func (*Client) ListValues added in v1.1.0

func (c *Client) ListValues(ctx context.Context, options ListValuesOptions) (ValueListResult, error)

ListValues returns matching property values without exposing traversal helper types.

func (*Client) S deprecated

S returns the legacy Gremlin traversal source.

Deprecated: use core-owned operation methods such as UpsertVertex for new code.

func (*Client) UpsertEdge added in v1.1.0

func (c *Client) UpsertEdge(ctx context.Context, options UpsertEdgeOptions) (GraphResult, error)

UpsertEdge upserts one edge with core-owned options.

func (*Client) UpsertVertex added in v1.1.0

func (c *Client) UpsertVertex(ctx context.Context, options UpsertVertexOptions) (GraphResult, error)

UpsertVertex upserts one vertex with core-owned options.

type CommonVertexGetter

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

func NewCommonVertexGetter

func NewCommonVertexGetter(vertex *gremlingo.Vertex, id string) CommonVertexGetter

func (CommonVertexGetter) Get

type Comparison added in v1.1.0

type Comparison string

Comparison identifies a core-owned property comparison operation.

const (
	// ComparisonEqual applies an equality property filter.
	ComparisonEqual Comparison = "eq"
	// ComparisonGreaterThan applies a greater-than property filter.
	ComparisonGreaterThan Comparison = "gt"
	// ComparisonGreaterThanOrEqual applies a greater-than-or-equal property filter.
	ComparisonGreaterThanOrEqual Comparison = "gte"
	// ComparisonLessThan applies a less-than property filter.
	ComparisonLessThan Comparison = "lt"
	// ComparisonLessThanOrEqual applies a less-than-or-equal property filter.
	ComparisonLessThanOrEqual Comparison = "lte"
)

type ConnectionConfig

type ConnectionConfig struct {
	URL string `env:"_URL" envDefault:"ws://127.0.0.1:8182/gremlin"`
}

ConnectionConfig contains required data for gremlin

func GetConnectionConfigFromEnv

func GetConnectionConfigFromEnv() (*ConnectionConfig, error)

GetConnectionConfigFromEnv return aerospike configs bases on environment variables

type CountResult added in v1.1.0

type CountResult struct {
	Count int64
}

CountResult is the core-owned result for count queries.

type CountVerticesOptions added in v1.1.0

type CountVerticesOptions struct {
	Label   string
	ID      string
	Filters []PropertyFilter
}

CountVerticesOptions is the core-owned input for vertex count queries.

type DropVertexOp

type DropVertexOp struct {
	*ResultOp
	// contains filtered or unexported fields
}

func NewDropVertexOp

func NewDropVertexOp(vertex VertexGetter) *DropVertexOp

func (*DropVertexOp) Execute

func (o *DropVertexOp) Execute(cache *Cache, source *gremlingo.GraphTraversalSource) error

type GraphResult added in v1.1.0

type GraphResult struct {
	Affected int64
}

GraphResult is the core-owned result for Gremlin graph operations.

type GraphStore added in v1.1.0

type GraphStore interface {
	VertexStore
	UpsertEdge(ctx context.Context, options UpsertEdgeOptions) (GraphResult, error)
	CountVertices(ctx context.Context, options CountVerticesOptions) (CountResult, error)
	ListValues(ctx context.Context, options ListValuesOptions) (ValueListResult, error)
}

GraphStore is the core-owned Gremlin contract for vertex, edge, and traversal helper operations.

type LabelVertexGetter

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

func NewLabelVertexGetter

func NewLabelVertexGetter(label string, id string) LabelVertexGetter

func (LabelVertexGetter) Get

type ListValuesOptions added in v1.1.0

type ListValuesOptions struct {
	Label    string
	ID       string
	Property string
	Filters  []PropertyFilter
}

ListValuesOptions is the core-owned input for listing property values.

type Operation

type Operation interface {
	Execute(cache *Cache, source *gremlingo.GraphTraversalSource) error
	Result() []*gremlingo.Result
}

type Options added in v1.1.0

type Options struct {
	URL string
}

Options is the core-owned input for creating a Gremlin client.

type PropertyFilter added in v1.1.0

type PropertyFilter struct {
	Name       string
	Comparison Comparison
	Value      any
}

PropertyFilter is a core-owned Gremlin property filter.

type ResultOp

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

func (*ResultOp) Result

func (o *ResultOp) Result() []*gremlingo.Result

type SyntaxConfig added in v1.1.0

type SyntaxConfig struct {
	Syntax string `env:"_SYNTAX" envDefault:""`
}

SyntaxConfig contains Gremlin syntax configuration.

func GetSyntaxConfigFromEnv added in v1.1.0

func GetSyntaxConfigFromEnv() (*SyntaxConfig, error)

GetSyntaxConfigFromEnv returns Gremlin syntax config from environment variables.

type SyntaxState added in v1.1.0

type SyntaxState struct {
	Syntax     string
	PropertyID interface{}
}

SyntaxState is an explicit Gremlin syntax configuration.

func CurrentSyntaxState added in v1.1.0

func CurrentSyntaxState() SyntaxState

CurrentSyntaxState returns the current legacy package-level syntax state.

func NewSyntaxState added in v1.1.0

func NewSyntaxState(syntax string) SyntaxState

NewSyntaxState creates a normalized Gremlin syntax state.

func SyntaxStateFromConfig added in v1.1.0

func SyntaxStateFromConfig(config SyntaxConfig) SyntaxState

SyntaxStateFromConfig creates a Gremlin syntax state from explicit config.

func SyntaxStateFromEnv deprecated added in v1.1.0

func SyntaxStateFromEnv() SyntaxState

SyntaxStateFromEnv reads Gremlin syntax config for legacy compatibility.

Deprecated: use GetSyntaxConfigFromEnv and SyntaxStateFromConfig in the application composition root.

type UpsertEdgeOp

type UpsertEdgeOp struct {
	*ResultOp
	// contains filtered or unexported fields
}

func NewUpsertEdgeOp

func NewUpsertEdgeOp(
	edge string,
	id string,
	from VertexGetter,
	to VertexGetter,
	properties ...interface{},
) *UpsertEdgeOp

func (*UpsertEdgeOp) Execute

func (o *UpsertEdgeOp) Execute(cache *Cache, source *gremlingo.GraphTraversalSource) error

type UpsertEdgeOptions added in v1.1.0

type UpsertEdgeOptions struct {
	Label      string
	ID         string
	From       VertexRef
	To         VertexRef
	Properties map[string]any
}

UpsertEdgeOptions is the core-owned input for an edge upsert.

type UpsertVertexOp

type UpsertVertexOp struct {
	*ResultOp
	// contains filtered or unexported fields
}

func NewUpsertVertexOp

func NewUpsertVertexOp(label string, id string, properties ...interface{}) *UpsertVertexOp

func (*UpsertVertexOp) Execute

func (o *UpsertVertexOp) Execute(cache *Cache, source *gremlingo.GraphTraversalSource) error

type UpsertVertexOptions added in v1.1.0

type UpsertVertexOptions struct {
	Label      string
	ID         string
	Properties map[string]any
}

UpsertVertexOptions is the core-owned input for a vertex upsert.

type ValueListResult added in v1.1.0

type ValueListResult struct {
	Values []any
}

ValueListResult is the core-owned result for value list queries.

type VertexGetter

type VertexGetter interface {
	Get(cache *Cache, source *gremlingo.GraphTraversalSource) (string, *gremlingo.Vertex, error)
}

type VertexRef added in v1.1.0

type VertexRef struct {
	Label string
	ID    string
}

VertexRef identifies a vertex without exposing Gremlin SDK vertex values.

type VertexStore added in v1.1.0

type VertexStore interface {
	UpsertVertex(ctx context.Context, options UpsertVertexOptions) (GraphResult, error)
	CloseGraph(ctx context.Context) error
}

VertexStore is the core-owned Gremlin contract for new consumers.

Jump to

Keyboard shortcuts

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