driver

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	P     = gremlingo.P
	Order = gremlingo.Order
	Scope = gremlingo.Scope
)

Functions

func Create

func Create[T any](db *GremlinDriver, value *T) error

func GetLabel added in v0.3.2

func GetLabel[T any]() string

func Save

func Save[T any](driver *GremlinDriver, v *T) error

func SliceToAnySlice added in v0.3.6

func SliceToAnySlice[T any](slice []T) []any

func ToMapTraversal added in v0.2.0

func ToMapTraversal(
	query *gremlingo.GraphTraversal,
	subtraversals map[string]*gremlingo.GraphTraversal,
	args ...any,
) *gremlingo.GraphTraversal

ToMapTraversal converts a Gremlin traversal to a map traversal using valuemap and projecting the subtraversals if there are no subtraversals, it will return the query.ValueMap(args...).By(

	anonymousTraversal.Choose(
		anonymousTraversal.Count(Scope.Local).Is(P.Eq(1)),
		anonymousTraversal.Unfold(),
		anonymousTraversal.Identity(),
	),
)

func UnloadGremlinResultIntoStruct added in v0.1.3

func UnloadGremlinResultIntoStruct(
	v any,
	result *gremlingo.Result,
) error

UnloadGremlinResultIntoStruct unloads a gremlin result into a struct it will recursively unload the result into the struct v any must be a pointer to a struct result *gremlingo.Result is the gremlin result to unload which must be a map note the struct must have gremlin tags on the fields to be unloaded

Types

type AfterCreateHook added in v0.2.11

type AfterCreateHook interface {
	AfterCreate(db *GremlinDriver) error
}

AfterCreateHook runs after create persists the vertex. Returning an error propagates to the caller.

type AfterFindHook added in v0.2.12

type AfterFindHook interface {
	AfterFind(db *GremlinDriver) error
}

AfterFindHook runs after a vertex has been loaded from the database. Returning an error propagates to the caller.

type AfterUpdateHook added in v0.2.11

type AfterUpdateHook interface {
	AfterUpdate(db *GremlinDriver) error
}

AfterUpdateHook runs after update persists the vertex. Returning an error propagates to the caller.

type BeforeCreateHook added in v0.2.11

type BeforeCreateHook interface {
	BeforeCreate(db *GremlinDriver) error
}

BeforeCreateHook runs before create persists the vertex. Returning an error aborts the create.

type BeforeUpdateHook added in v0.2.11

type BeforeUpdateHook interface {
	BeforeUpdate(db *GremlinDriver) error
}

BeforeUpdateHook runs before update persists the vertex. Returning an error aborts the update.

type Config added in v0.3.1

type Config struct {
	Driver                    DatabaseDriver
	IDGenerator               func() any
	GremlinConnectionSettings func(settings *gremlingo.DriverRemoteConnectionSettings)
}

type DatabaseDriver added in v0.1.0

type DatabaseDriver string
const (
	Gremlin DatabaseDriver = "gremlin"
	Neptune DatabaseDriver = "neptune"
)

type GremlinDriver

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

func Open

func Open(url string, config ...Config) (*GremlinDriver, error)

func (*GremlinDriver) Close

func (driver *GremlinDriver) Close()

func (*GremlinDriver) G added in v0.2.10

G exposes the traversal source for building custom traversals.

func (*GremlinDriver) Label

func (driver *GremlinDriver) Label(label string) *RawQuery

Label returns a query builder for a specific label

type GremlinOrder

type GremlinOrder int
const (
	Asc GremlinOrder = iota
	Desc
)

type OrderCondition

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

type Query

type Query[T any] struct {
	// contains filtered or unexported fields
}

Query represents a chainable query builder

func Model

func Model[T any](driver *GremlinDriver) *Query[T]

Model returns a new query builder for the specified type

func NewQuery

func NewQuery[T any](db *GremlinDriver) *Query[T]

NewQuery creates a new query builder for type T

func Where

func Where[T any](
	driver *GremlinDriver,
	field string,
	operator comparator.Comparator,
	value any,
) *Query[T]

Where is a convenience method that creates a new query with a condition

func (*Query[T]) AddSubTraversal added in v0.2.0

func (q *Query[T]) AddSubTraversal(
	gremlinTag string,
	traversal *gremlingo.GraphTraversal,
) *Query[T]

AddSubTraversal adds a single subtraversal to the query This is useful when you need to fetch related data or perform complex traversals that should populate a specific field in your struct. You will need to signal this in your struct tags with the gremlinSubTraversal tag.

func (*Query[T]) AddSubTraversals added in v0.2.0

func (q *Query[T]) AddSubTraversals(subTraversals map[string]*gremlingo.GraphTraversal) *Query[T]

AddSubTraversals adds multiple subtraversals to the query This is useful when you need to fetch related data or perform complex traversals that should populate specific fields in your struct. You will need to signal this in your struct tags with the gremlinSubTraversal tag.

func (*Query[T]) BuildQuery added in v0.1.3

func (q *Query[T]) BuildQuery() *gremlingo.GraphTraversal

BuildQuery constructs the Gremlin traversal from the query conditions

func (*Query[T]) Count

func (q *Query[T]) Count() (int, error)

Count returns the number of matching results

func (*Query[T]) Dedup

func (q *Query[T]) Dedup() *Query[T]

Dedup removes duplicate results from the query

func (*Query[T]) Delete

func (q *Query[T]) Delete() error

Delete deletes all matching results

func (*Query[T]) Find

func (q *Query[T]) Find() ([]T, error)

Find executes the query and returns all matching results

func (*Query[T]) ID added in v0.1.0

func (q *Query[T]) ID(id any) (T, error)

ID finds vertex by id in a more optimized way than using where

func (*Query[T]) IDs added in v0.1.3

func (q *Query[T]) IDs(id ...any) *Query[T]

IDs adds the ids to the query You can use this to speed up the query by using the graph index

func (*Query[T]) Labels added in v0.3.6

func (q *Query[T]) Labels(labels ...string) *Query[T]

Labels adds labels to the query This is useful when you need to filter by multiple labels You can use this to speed up the query by using the graph index Note this will override any label set via the Label() method or pre computed label

func (*Query[T]) Limit

func (q *Query[T]) Limit(limit int) *Query[T]

Limit sets the maximum number of results

func (*Query[T]) Offset

func (q *Query[T]) Offset(offset int) *Query[T]

Offset sets the number of results to skip

func (*Query[T]) OrderBy

func (q *Query[T]) OrderBy(field string, order GremlinOrder) *Query[T]

OrderBy adds ordering to the query

func (*Query[T]) PreQuery added in v0.2.10

func (q *Query[T]) PreQuery(traversal *gremlingo.GraphTraversal) *Query[T]

PreQuery sets a traversal to run before applying query conditions. When set, it replaces the default V() start for the query.

func (*Query[T]) Range added in v0.2.8

func (q *Query[T]) Range(lower int, upper int) *Query[T]

Range sets the range of the query This is useful when you need to get a range of results It will be ignored if offset is set Note the range is inclusive of lower bound and exclusive of upper bound Examples:

  • Range(0, 10) will return results 0-9
  • Range(10, 20) will return results 10-19
  • Range(0, 20) will return results 0-19

func (*Query[T]) Select added in v0.3.6

func (q *Query[T]) Select(fields ...string) *Query[T]

Select adds selected fields to the query

func (*Query[T]) Take

func (q *Query[T]) Take() (T, error)

Take executes the query and returns the first result

func (*Query[T]) Update

func (q *Query[T]) Update(propertyName string, value any) error

Update updates a property of the struct NOTE: Slices will be updated as Cardinality.Set NOTE: Maps will be updated as Cardinality.Set with keys as the value of the property

func (*Query[T]) Where

func (q *Query[T]) Where(field string, operator comparator.Comparator, value any) *Query[T]

Where adds a condition to the query

func (*Query[T]) WhereTraversal

func (q *Query[T]) WhereTraversal(traversal *gremlingo.GraphTraversal) *Query[T]

WhereTraversal adds a custom Gremlin traversal condition

type QueryCondition

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

func (*QueryCondition) String added in v0.1.0

func (qc *QueryCondition) String() string

type QueryOpts

type QueryOpts struct {
	ID    any
	Where *gremlingo.GraphTraversal
}

type RangeCondition added in v0.2.8

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

type RawQuery

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

RawQuery for dynamic queries without type constraints

func (*RawQuery) Has

func (rq *RawQuery) Has(key string, value any) *RawQuery

func (*RawQuery) Limit

func (rq *RawQuery) Limit(limit int) *RawQuery

func (*RawQuery) Next

func (rq *RawQuery) Next() (*gremlingo.Result, error)

func (*RawQuery) ToList

func (rq *RawQuery) ToList() ([]*gremlingo.Result, error)

func (*RawQuery) Where

func (rq *RawQuery) Where(traversal *gremlingo.GraphTraversal) *RawQuery

Jump to

Keyboard shortcuts

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