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
- Variables
- func ApplySyntaxState(state SyntaxState)deprecated
- func ExecIterate(ch <-chan error) error
- func GetConnection(cfg *ConnectionConfig, ...) (*gremlingo.DriverRemoteConnection, error)deprecated
- func InstallSyntaxState(state SyntaxState) func()deprecated
- func MergeE(t *gremlingo.GraphTraversal, edge string, id string, ...) *gremlingo.GraphTraversal
- func MergeV(t *gremlingo.GraphTraversal, label, id string, ...) *gremlingo.GraphTraversal
- func PrepareProperties(properties ...interface{}) map[interface{}]interface{}
- func Setup(state SyntaxState)
- func WrapCount(t *gremlingo.GraphTraversal) (int64, error)
- func WrapLabelFilter(t *gremlingo.GraphTraversal, label string) *gremlingo.GraphTraversal
- func WrapOrderAsc(t *gremlingo.GraphTraversal, property string) *gremlingo.GraphTraversal
- func WrapOrderDesc(t *gremlingo.GraphTraversal, property string) *gremlingo.GraphTraversal
- func WrapOrderGt(t *gremlingo.GraphTraversal, property string, value interface{}) *gremlingo.GraphTraversal
- func WrapOrderGte(t *gremlingo.GraphTraversal, property string, value interface{}) *gremlingo.GraphTraversal
- func WrapOrderLt(t *gremlingo.GraphTraversal, property string, value interface{}) *gremlingo.GraphTraversal
- func WrapOrderLte(t *gremlingo.GraphTraversal, property string, value interface{}) *gremlingo.GraphTraversal
- func WrapValuesToList(t *gremlingo.GraphTraversal, values string) ([]*gremlingo.Result, error)
- func WrapperHasID(t *gremlingo.GraphTraversal, id string) *gremlingo.GraphTraversal
- type Cache
- type CallbackOp
- type Clientdeprecated
- func (c *Client) Close()
- func (c *Client) CloseGraph(ctx context.Context) error
- func (c *Client) CountVertices(ctx context.Context, options CountVerticesOptions) (CountResult, error)
- func (c *Client) Execute(cache *Cache, ops ...Operation) error
- func (c *Client) ListValues(ctx context.Context, options ListValuesOptions) (ValueListResult, error)
- func (c *Client) S() *gremlingo.GraphTraversalSourcedeprecated
- func (c *Client) UpsertEdge(ctx context.Context, options UpsertEdgeOptions) (GraphResult, error)
- func (c *Client) UpsertVertex(ctx context.Context, options UpsertVertexOptions) (GraphResult, error)
- type CommonVertexGetter
- type Comparison
- type ConnectionConfig
- type CountResult
- type CountVerticesOptions
- type DropVertexOp
- type GraphResult
- type GraphStore
- type LabelVertexGetter
- type ListValuesOptions
- type Operation
- type Options
- type PropertyFilter
- type ResultOp
- type SyntaxConfig
- type SyntaxState
- type UpsertEdgeOp
- type UpsertEdgeOptions
- type UpsertVertexOp
- type UpsertVertexOptions
- type ValueListResult
- type VertexGetter
- type VertexRef
- type VertexStore
Constants ¶
const ( SyntaxAerospike = "aerospike" SyntaxNeptun = "neptun" DefaultPropertyID = "id" )
const EnvPrefix = "GREMLIN"
EnvPrefix environment prefix for gremlin config
Variables ¶
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 )
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 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 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 WrapperHasID ¶
func WrapperHasID(t *gremlingo.GraphTraversal, id string) *gremlingo.GraphTraversal
Types ¶
type Cache ¶
type Cache struct {
*registry.Registry[string, string, any]
// contains filtered or unexported fields
}
func (*Cache) DeleteVertex ¶
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 (*Client) CloseGraph ¶ added in v1.1.0
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) 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
func (c *Client) S() *gremlingo.GraphTraversalSource
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 ¶
func (v CommonVertexGetter) Get(_ *Cache, _ *gremlingo.GraphTraversalSource) (string, *gremlingo.Vertex, error)
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 ¶
func (v LabelVertexGetter) Get( cache *Cache, source *gremlingo.GraphTraversalSource, ) (string, *gremlingo.Vertex, error)
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 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 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
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 VertexRef ¶ added in v1.1.0
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.