dsl

package
v0.11.10 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: Apache-2.0 Imports: 3 Imported by: 33

Documentation

Overview

Package dsl provide an API for writing gremlin dsl queries almost as-is in Go without using strings in the code.

Note that, the API is not type-safe and assume the provided query and its arguments are valid.

Index

Constants

This section is empty.

Variables

View Source
var (
	G   = Token("g")
	Dot = Token(".")
)

predefined nodes.

Functions

This section is empty.

Types

type Bindings

type Bindings map[string]any

Bindings are used to associate a variable with a value.

func (Bindings) Add

func (b Bindings) Add(v any) string

Add adds new value to the bindings map, formats it if needed, and returns its generated name.

type Block

type Block struct {
	Nodes []any
}

Block represents a block/group of nodes.

func (Block) Code

func (b Block) Code() (string, []any)

Code returns the code representation of group/block of nodes.

type Cardinality

type Cardinality string

Cardinality of vertex properties.

const (
	Set    Cardinality = "set"
	Single Cardinality = "single"
)

Cardinality options.

func (Cardinality) Code

func (c Cardinality) Code() (string, []any)

Code implements the Node interface.

type Column

type Column string

Column references a particular type of column in a complex data structure such as a Map, a Map.Entry, or a Path.

const (
	Keys   Column = "keys"
	Values Column = "values"
)

Column options.

func (Column) Code

func (o Column) Code() (string, []any)

Code implements the Node interface.

type Func

type Func struct {
	Name string
	Args []any
}

Func represents a function call.

func NewFunc

func NewFunc(name string, args ...any) *Func

NewFunc returns a new function node.

func (Func) Code

func (f Func) Code() (string, []any)

Code returns the code representation of a function call.

type Keyword added in v0.9.0

type Keyword string

Keyword defines a Gremlin keyword.

const (
	ID Keyword = "id"
)

Keyword options.

func (Keyword) Code added in v0.9.0

func (k Keyword) Code() (string, []any)

Code implements the Node interface.

type List

type List struct {
	Elements []any
}

List represents a list of elements.

func NewList

func NewList(args ...any) *List

NewList returns a new list node.

func (List) Code

func (l List) Code() (string, []any)

Code returns the code representation of a list.

type Node

type Node interface {
	// Code returns the code representation of the element and its bindings (if any).
	Code() (string, []any)
}

Node represents a DSL step in the traversal.

type Order

type Order string

Order of vertex properties.

const (
	Incr    Order = "incr"
	Decr    Order = "decr"
	Shuffle Order = "shuffle"
)

Order options.

func (Order) Code

func (o Order) Code() (string, []any)

Code implements the Node interface.

type Querier

type Querier interface {
	// Query returns the query-string (similar to the Gremlin byte-code) and its bindings.
	Query() (string, Bindings)
}

Querier is the interface that wraps the Query method.

type Scope

type Scope string

Scope used for steps that have a variable scope which alter the manner in which the step will behave in relation to how the traverses are processed.

const (
	Local  Scope = "local"
	Global Scope = "global"
)

Scope options.

func (Scope) Code

func (s Scope) Code() (string, []any)

Code implements the Node interface.

type Token

type Token string

Token holds a simple token, like assignment.

func (Token) Code

func (t Token) Code() (string, []any)

Code stringified the token.

type Traversal

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

Traversal mimics the TinkerPop graph traversal.

func Each

func Each(v any, cb func(it *Traversal) *Traversal) *Traversal

Each is a Groovy each-loop function.

func Group

func Group(trs ...*Traversal) *Traversal

Group groups a list of traversals into one. all traversals are assigned into a temporary variables named by their index. The last variable functions as a return value of the query. Note that, this "temporary hack" is not perfect and may not work in some cases because of the limitation of evaluation order.

func Join

func Join(trs ...*Traversal) *Traversal

Join joins a list of traversals with a semicolon separator.

func NewTraversal

func NewTraversal() *Traversal

NewTraversal returns a new default traversal with "g" as a reference name to the Graph.

func (*Traversal) Add

func (t *Traversal) Add(n ...Node) *Traversal

Add is the public API for adding new nodes to the traversal by its sub packages.

func (*Traversal) AddE

func (t *Traversal) AddE(args ...any) *Traversal

AddE adds an edge.

func (*Traversal) AddV

func (t *Traversal) AddV(args ...any) *Traversal

AddV adds a vertex.

func (*Traversal) And

func (t *Traversal) And(args ...any) *Traversal

And ensures that all of the provided traversals yield a result.

func (*Traversal) As

func (t *Traversal) As(args ...any) *Traversal

As provides a label to the step that can be accessed later in the traversal by other steps.

func (*Traversal) Both

func (t *Traversal) Both(args ...any) *Traversal

Both maps the Vertex to its adjacent vertices given the edge labels.

func (*Traversal) BothE

func (t *Traversal) BothE(args ...any) *Traversal

BothE maps the Vertex to its incident edges given the edge labels.

func (*Traversal) By

func (t *Traversal) By(args ...any) *Traversal

By can be applied to a number of different step to alter their behaviors. This form is essentially an identity() modulation.

func (*Traversal) Choose

func (t *Traversal) Choose(args ...any) *Traversal

Choose routes the current traverser to a particular traversal branch option which allows the creation of if-then-else like semantics within a traversal.

func (*Traversal) Clone

func (t *Traversal) Clone() *Traversal

Clone creates a deep copy of an existing traversal.

func (*Traversal) Coalesce

func (t *Traversal) Coalesce(args ...any) *Traversal

Coalesce evaluates the provided traversals and returns the result of the first traversal to emit at least one object.

func (*Traversal) Constant

func (t *Traversal) Constant(args ...any) *Traversal

Constant maps any object to a fixed E value.

func (*Traversal) Count

func (t *Traversal) Count(args ...any) *Traversal

Count maps the traversal stream to its reduction as a sum of the Traverser.bulk() values (i.e. count the number of traversers up to this point).

func (*Traversal) Dedup

func (t *Traversal) Dedup(args ...any) *Traversal

Dedup removes all duplicates in the traversal stream up to this point.

func (*Traversal) Drop

func (t *Traversal) Drop() *Traversal

Drop removes elements and properties from the graph.

func (*Traversal) E

func (t *Traversal) E(args ...any) *Traversal

E step is usually used to start a traversal but it may also be used mid-traversal.

func (*Traversal) Fold

func (t *Traversal) Fold() *Traversal

Fold rolls up objects in the stream into an aggregate list..

func (*Traversal) From

func (t *Traversal) From(args ...any) *Traversal

From provides from()-modulation to respective steps.

func (*Traversal) Group

func (t *Traversal) Group() *Traversal

Group organizes objects in the stream into a Map.Calls to group() are typically accompanied with by() modulators which help specify how the grouping should occur.

func (*Traversal) Has

func (t *Traversal) Has(args ...any) *Traversal

Has filters vertices, edges and vertex properties based on their properties. See: http://tinkerpop.apache.org/docs/current/reference/#has-step.

func (*Traversal) HasID

func (t *Traversal) HasID(args ...any) *Traversal

HasID filters vertices, edges and vertex properties based on their identifier.

func (*Traversal) HasLabel

func (t *Traversal) HasLabel(args ...any) *Traversal

HasLabel filters vertices, edges and vertex properties based on their label.

func (*Traversal) HasNext

func (t *Traversal) HasNext() *Traversal

HasNext returns true if the iteration has more elements.

func (*Traversal) HasNot

func (t *Traversal) HasNot(args ...any) *Traversal

HasNot filters vertices, edges and vertex properties based on the non-existence of properties. See: http://tinkerpop.apache.org/docs/current/reference/#has-step.

func (*Traversal) ID

func (t *Traversal) ID() *Traversal

ID maps the Element to its Element.id().

func (*Traversal) In

func (t *Traversal) In(args ...any) *Traversal

In maps the Vertex to its incoming adjacent vertices given the edge labels.

func (*Traversal) InE

func (t *Traversal) InE(args ...any) *Traversal

InE maps the Vertex to its incoming incident edges given the edge labels.

func (*Traversal) InV

func (t *Traversal) InV(args ...any) *Traversal

InV maps the Edge to its incoming/head incident Vertex.

func (*Traversal) Is

func (t *Traversal) Is(args ...any) *Traversal

Is filters the E object if it is not P.eq(V) to the provided value.

func (*Traversal) Iterate

func (t *Traversal) Iterate() *Traversal

Iterate iterates the traversal presumably for the generation of side-effects.

func (*Traversal) Label

func (t *Traversal) Label() *Traversal

Label maps the Element to its Element.label().

func (*Traversal) Limit

func (t *Traversal) Limit(args ...any) *Traversal

Limit filters the objects in the traversal by the number of them to pass through the stream, where only the first n objects are allowed as defined by the limit argument.

func (*Traversal) Match

func (t *Traversal) Match(args ...any) *Traversal

Match maps the Traverser to a Map of bindings as specified by the provided match traversals.

func (*Traversal) Max

func (t *Traversal) Max(args ...any) *Traversal

Max determines the greatest value in the stream.

func (*Traversal) Mean

func (t *Traversal) Mean(args ...any) *Traversal

Mean determines the mean value in the stream.

func (*Traversal) Min

func (t *Traversal) Min(args ...any) *Traversal

Min determines the smallest value in the stream.

func (*Traversal) Next

func (t *Traversal) Next() *Traversal

Next gets the next n-number of results from the traversal.

func (*Traversal) Not

func (t *Traversal) Not(args ...any) *Traversal

Not removes objects from the traversal stream when the traversal provided as an argument does not return any objects.

func (*Traversal) Or

func (t *Traversal) Or(args ...any) *Traversal

Or ensures that at least one of the provided traversals yield a result.

func (*Traversal) Order

func (t *Traversal) Order(args ...any) *Traversal

Order all the objects in the traversal up to this point and then emit them one-by-one in their ordered sequence.

func (*Traversal) OtherV

func (t *Traversal) OtherV() *Traversal

OtherV maps the Edge to the incident vertex that was not just traversed from in the path history.

func (*Traversal) Out

func (t *Traversal) Out(args ...any) *Traversal

Out maps the Vertex to its outgoing adjacent vertices given the edge labels.

func (*Traversal) OutE

func (t *Traversal) OutE(args ...any) *Traversal

OutE maps the Vertex to its outgoing incident edges given the edge labels.

func (*Traversal) OutV

func (t *Traversal) OutV(args ...any) *Traversal

OutV maps the Edge to its outgoing/tail incident Vertex.

func (*Traversal) Properties

func (t *Traversal) Properties(args ...any) *Traversal

Properties maps the Element to its associated properties given the provide property keys.

func (*Traversal) Property

func (t *Traversal) Property(args ...any) *Traversal

Property sets a Property value and related meta properties if supplied, if supported by the Graph and if the Element is a VertexProperty.

func (*Traversal) Query

func (t *Traversal) Query() (string, Bindings)

Query returns the query-representation and its binding of this traversal object.

func (*Traversal) Range

func (t *Traversal) Range(args ...any) *Traversal

Range filters the objects in the traversal by the number of them to pass through the stream.

func (*Traversal) Select

func (t *Traversal) Select(args ...any) *Traversal

Select arbitrary values from the traversal.

func (*Traversal) SideEffect

func (t *Traversal) SideEffect(args ...any) *Traversal

SideEffect allows the traverser to proceed unchanged, but yield some computational sideEffect in the process.

func (*Traversal) Sum

func (t *Traversal) Sum(args ...any) *Traversal

Sum maps the traversal stream to its reduction as a sum of the Traverser.get() values multiplied by their Traverser.bulk().

func (*Traversal) To

func (t *Traversal) To(args ...any) *Traversal

To used as a modifier to addE(String) this method specifies the traversal to use for selecting the incoming vertex of the newly added Edge.

func (*Traversal) ToList

func (t *Traversal) ToList() *Traversal

ToList puts all the results into a Groovy list.

func (*Traversal) Undo

func (t *Traversal) Undo() *Traversal

Undo reverts the last-step of the traversal.

func (*Traversal) Unfold

func (t *Traversal) Unfold() *Traversal

Unfold unrolls a Iterator, Iterable or Map into a linear form or simply emits the object if it is not one of those types.

func (*Traversal) Union

func (t *Traversal) Union(args ...any) *Traversal

Union merges the results of an arbitrary number of traversals.

func (*Traversal) V

func (t *Traversal) V(args ...any) *Traversal

V step is usually used to start a traversal but it may also be used mid-traversal.

func (*Traversal) ValueMap

func (t *Traversal) ValueMap(args ...any) *Traversal

ValueMap maps the Element to a Map of the property values key'd according to their Property.key().

func (*Traversal) Values

func (t *Traversal) Values(args ...string) *Traversal

Values maps the Element to the values of the associated properties given the provide property keys.

func (*Traversal) Where

func (t *Traversal) Where(args ...any) *Traversal

Where filters the current object based on the object itself or the path history.

type Var

type Var struct {
	Name string
	Elem any
}

Var represents a variable assignment and usage.

func (Var) Code

func (v Var) Code() (string, []any)

Code returns the code representation of variable declaration or its identifier.

Directories

Path Synopsis
g
p

Jump to

Keyboard shortcuts

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