gremgo

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 18 Imported by: 6

README

gremgo-neptune

gremgo-neptune is a fork of qasaur/gremgo with alterations to make it compatible with AWS Neptune which is a "Fast, reliable graph database built for the cloud".

gremgo is a fast, efficient, and easy-to-use client for the TinkerPop graph database stack. It is a Gremlin language driver which uses WebSockets to interface with Gremlin Server and has a strong emphasis on concurrency and scalability. Please keep in mind that gremgo is still under heavy development and although effort is being made to fully cover gremgo with reliable tests, bugs may be present in several areas.

Modifications were made to gremgo in order to "support" AWS Neptune's lack of Gremlin-specific features, like no support for query bindings, among others. See differences in Gremlin support here: AWS Neptune Gremlin Implementation Differences

Installation

go get github.com/ONSdigital/gremgo-neptune
dep ensure

Development

If you amend the dialer interface, please run:

go generate

Documentation

Examples

License

See LICENSE

Documentation

Index

Constants

View Source
const (
	StatusSuccess                  = 200
	StatusNoContent                = 204
	StatusPartialContent           = 206
	StatusUnauthorized             = 401
	StatusAuthenticate             = 407
	StatusMalformedRequest         = 498
	StatusInvalidRequestArguments  = 499
	StatusServerError              = 500
	StatusScriptEvaluationError    = 597
	StatusServerTimeout            = 598
	StatusServerSerializationError = 599
)

Variables

View Source
var (
	ErrorConnectionDisposed      = errors.New("you cannot write on a disposed connection")
	ErrorNoGraphTags             = errors.New("does not contain any graph tags")
	ErrorUnsupportedPropertyType = errors.New("unsupported property map value type")
)
View Source
var (
	ErrGraphDBClosed = errors.New("graphdb is closed")
	ErrBadConn       = errors.New("bad conn")
)

errors

Functions

func GremlinForVertex

func GremlinForVertex(label string, data interface{}) (gremAdd, gremGet string, err error)

GremlinForVertex returns the addV()... and V()... gremlin commands for `data` Because of possible multiples, it does not start with `g.` (it probably should? XXX ) (largely taken from https://github.com/intwinelabs/gremgoser)

Types

type Client

type Client struct {
	sync.Mutex
	Errored bool
	// contains filtered or unexported fields
}

Client is a container for the gremgo client.

func Dial

func Dial(conn dialer, errs chan error) (c *Client, err error)

Dial returns a gremgo client for interaction with the Gremlin Server specified in the host IP.

func DialCtx

func DialCtx(ctx context.Context, conn dialer, errs chan error) (c *Client, err error)

DialCtx returns a gremgo client for interaction with the Gremlin Server specified in the host IP.

func (*Client) AddE

func (c *Client) AddE(label, fromId, toId string, props map[string]interface{}) (resp interface{}, err error)

AddE takes a label, from UUID and to UUID (and optional props map) and creates an edge between the two vertex in the graph

func (*Client) AddEdgeCtx

func (c *Client) AddEdgeCtx(ctx context.Context, label, fromId, toId string, props map[string]interface{}) (resp interface{}, err error)

func (*Client) AddV

func (c *Client) AddV(label string, data interface{}, bindings, rebindings map[string]string) (vert graphson.Vertex, err error)

AddV takes a label and an interface and adds it as a vertex to the graph

func (*Client) AddVertexCtx

func (c *Client) AddVertexCtx(ctx context.Context, label string, data interface{}, bindings, rebindings map[string]string) (vert graphson.Vertex, err error)

func (*Client) Close

func (c *Client) Close()

Close closes the underlying connection and marks the client as closed.

func (*Client) Execute

func (c *Client) Execute(query string, bindings, rebindings map[string]string) (resp []Response, err error)

Execute formats a raw Gremlin query, sends it to Gremlin Server, and returns the result.

func (*Client) ExecuteCtx

func (c *Client) ExecuteCtx(ctx context.Context, query string, bindings, rebindings map[string]string) (resp []Response, err error)

func (*Client) ExecuteFile

func (c *Client) ExecuteFile(path string, bindings, rebindings map[string]string) (resp []Response, err error)

ExecuteFile takes a file path to a Gremlin script, sends it to Gremlin Server, and returns the result.

func (*Client) Get

func (c *Client) Get(query string, bindings, rebindings map[string]string) (res []graphson.Vertex, err error)

Get formats a raw Gremlin query, sends it to Gremlin Server, and populates the passed []interface.

func (*Client) GetCount

func (c *Client) GetCount(query string, bindings, rebindings map[string]string) (i int64, err error)

GetCount returns the count element returned by an Execute()

func (*Client) GetCountCtx

func (c *Client) GetCountCtx(ctx context.Context, query string, bindings, rebindings map[string]string) (i int64, err error)

func (*Client) GetCtx

func (c *Client) GetCtx(ctx context.Context, query string, bindings, rebindings map[string]string) (res []graphson.Vertex, err error)

GetCtx - execute a gremlin command and return the response as vertices

func (*Client) GetE

func (c *Client) GetE(query string, bindings, rebindings map[string]string) (res []graphson.Edge, err error)

GetE formats a raw Gremlin query, sends it to Gremlin Server, and populates the passed []interface.

func (*Client) GetEdgeCtx

func (c *Client) GetEdgeCtx(ctx context.Context, query string, bindings, rebindings map[string]string) (res []graphson.Edge, err error)

func (*Client) GetProperties

func (c *Client) GetProperties(query string, bindings, rebindings map[string]string) (vals map[string][]interface{}, err error)

GetProperties returns a map of string to interface{} returned by an Execute() for vertex .properties()

func (*Client) GetPropertiesCtx

func (c *Client) GetPropertiesCtx(ctx context.Context, query string, bindings, rebindings map[string]string) (vals map[string][]interface{}, err error)

func (*Client) GetStringList

func (c *Client) GetStringList(query string, bindings, rebindings map[string]string) (vals []string, err error)

GetStringList returns the list of string elements returned by an Execute() (e.g. from `...().properties('p').value()`)

func (*Client) GetStringListCtx

func (c *Client) GetStringListCtx(ctx context.Context, query string, bindings, rebindings map[string]string) (vals []string, err error)

func (*Client) OpenCursorCtx

func (c *Client) OpenCursorCtx(ctx context.Context, query string, bindings, rebindings map[string]string) (cursor *Cursor, err error)

OpenCursorCtx initiates a query on the database, returning a cursor used to iterate over the results as they arrive. The provided query must return a vertex or list of vertices in order for ReadCursorCtx to correctly format the results.

func (*Client) OpenStreamCursor

func (c *Client) OpenStreamCursor(ctx context.Context, query string, bindings, rebindings map[string]string) (*Stream, error)

OpenStreamCursor initiates a query on the database, returning a stream cursor used to iterate over the results as they arrive. The provided query must only return a string list, as the Read() function on Stream explicitly handles string values.

func (*Client) ReadCursorCtx

func (c *Client) ReadCursorCtx(ctx context.Context, cursor *Cursor) (res []graphson.Vertex, eof bool, err error)

ReadCursorCtx returns the next set of results, deserialized as []Vertex, for the cursor - `res` may be empty when results were read by a previous call - `eof` will be true when no more results are available

type Cursor

type Cursor struct {
	ID string
}

Cursor allows for results to be iterated over as soon as available, rather than waiting for a query to complete and all results to be returned in one block.

type DialerConfig

type DialerConfig func(*Ws)

DialerConfig is the struct for defining configuration for WebSocket dialer

func SetAuthentication

func SetAuthentication(username string, password string) DialerConfig

SetAuthentication sets on dialer credentials for authentication

func SetPingInterval

func SetPingInterval(seconds int) DialerConfig

SetPingInterval sets the interval of ping sending for know is connection is alive and in consequence the client is connected

func SetReadingWait

func SetReadingWait(seconds int) DialerConfig

SetReadingWait sets the time for waiting that reading occur

func SetTLSClientConfig added in v1.1.0

func SetTLSClientConfig(conf *tls.Config) DialerConfig

SetTLSClientConfig sets the TLS client config for the underlying websocket connection

func SetTimeout

func SetTimeout(seconds int) DialerConfig

SetTimeout sets the dial timeout

func SetWritingWait

func SetWritingWait(seconds int) DialerConfig

SetWritingWait sets the time for waiting that writing occur

type Pool

type Pool struct {
	MaxOpen     int
	MaxLifetime time.Duration
	// contains filtered or unexported fields
}

Pool maintains a list of connections.

func NewPool

func NewPool(dial func() (*Client, error)) *Pool

NewPool create ConnectionPool

func NewPoolWithDialerCtx

func NewPoolWithDialerCtx(ctx context.Context, dbURL string, errs chan error, cfgs ...DialerConfig) *Pool

NewPoolWithDialerCtx returns a NewPool that uses a contextual dialer to dbURL, errs is a chan that receives any errors from the ping/read/write workers for the connection

func (*Pool) AddE

func (p *Pool) AddE(label, fromId, toId string, props map[string]interface{}) (resp interface{}, err error)

AddE

func (*Pool) AddEdgeCtx

func (p *Pool) AddEdgeCtx(ctx context.Context, label, fromId, toId string, props map[string]interface{}) (resp interface{}, err error)

func (*Pool) AddV

func (p *Pool) AddV(label string, i interface{}, bindings, rebindings map[string]string) (resp graphson.Vertex, err error)

AddV

func (*Pool) AddVertexCtx

func (p *Pool) AddVertexCtx(ctx context.Context, label string, i interface{}, bindings, rebindings map[string]string) (resp graphson.Vertex, err error)

func (*Pool) Close

func (p *Pool) Close()

Close closes the pool.

func (*Pool) Execute

func (p *Pool) Execute(query string, bindings, rebindings map[string]string) (resp []Response, err error)

Execute formats a raw Gremlin query, sends it to Gremlin Server, and returns the result.

func (*Pool) ExecuteCtx

func (p *Pool) ExecuteCtx(ctx context.Context, query string, bindings, rebindings map[string]string) (resp []Response, err error)

func (*Pool) ExecuteFile

func (p *Pool) ExecuteFile(path string, bindings, rebindings map[string]string) (resp []Response, err error)

ExecuteFile takes a file path to a Gremlin script, sends it to Gremlin Server, and returns the result.

func (*Pool) Get

func (p *Pool) Get(query string, bindings, rebindings map[string]string) (resp []graphson.Vertex, err error)

Get

func (*Pool) GetCount

func (p *Pool) GetCount(q string, bindings, rebindings map[string]string) (i int64, err error)

func (*Pool) GetCountCtx

func (p *Pool) GetCountCtx(ctx context.Context, q string, bindings, rebindings map[string]string) (i int64, err error)

func (*Pool) GetCtx

func (p *Pool) GetCtx(ctx context.Context, query string, bindings, rebindings map[string]string) (resp []graphson.Vertex, err error)

GetCtx

func (*Pool) GetE

func (p *Pool) GetE(q string, bindings, rebindings map[string]string) (resp interface{}, err error)

GetE

func (*Pool) GetEdgeCtx

func (p *Pool) GetEdgeCtx(ctx context.Context, q string, bindings, rebindings map[string]string) (resp interface{}, err error)

func (*Pool) GetProperties

func (p *Pool) GetProperties(q string, bindings, rebindings map[string]string) (vals map[string][]interface{}, err error)

GetProperties returns a map of vertex properties

func (*Pool) GetPropertiesCtx

func (p *Pool) GetPropertiesCtx(ctx context.Context, q string, bindings, rebindings map[string]string) (vals map[string][]interface{}, err error)

func (*Pool) GetStringList

func (p *Pool) GetStringList(q string, bindings, rebindings map[string]string) (vals []string, err error)

func (*Pool) GetStringListCtx

func (p *Pool) GetStringListCtx(ctx context.Context, q string, bindings, rebindings map[string]string) (vals []string, err error)

func (*Pool) OpenCursorCtx

func (p *Pool) OpenCursorCtx(ctx context.Context, query string, bindings, rebindings map[string]string) (cursor *Cursor, err error)

OpenCursorCtx initiates a query on the database, returning a cursor to iterate over the results

func (*Pool) OpenStreamCursor

func (p *Pool) OpenStreamCursor(ctx context.Context, query string, bindings, rebindings map[string]string) (stream *Stream, err error)

OpenStreamCursor initiates a query on the database, returning a stream to iterate over the results

func (*Pool) ReadCursorCtx

func (p *Pool) ReadCursorCtx(ctx context.Context, cursor *Cursor) (res []graphson.Vertex, eof bool, err error)

ReadCursorCtx returns the next set of results for the cursor - `res` returns vertices (and may be empty when results were read by a previous call - this is normal) - `eof` will be true when no more results are available (`res` may still have results)

type Response

type Response struct {
	RequestID string `json:"requestId"`
	Status    Status `json:"status"`
	Result    Result `json:"result"`
}

Response structs holds the entire response from requests to the gremlin server

func (Response) ToString

func (r Response) ToString() string

ToString returns a string representation of the Response struct

type Result

type Result struct {
	// Query Response Data
	Data json.RawMessage        `json:"data"`
	Meta map[string]interface{} `json:"meta"`
}

Result struct is used to hold properties returned for results from requests to the gremlin server

type Retriever

type Retriever interface {
	// contains filtered or unexported methods
}

type Status

type Status struct {
	Message    string                 `json:"message"`
	Code       int                    `json:"code"`
	Attributes map[string]interface{} `json:"attributes"`
}

Status struct is used to hold properties returned from requests to the gremlin server

type Stream

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

Stream is a specific implementation of a Cursor, which iterates over results from a cursor but only works on queries which return a list of strings. This is designed for returning what would be considered 'rows' of data in other contexts.

func (*Stream) Close

func (s *Stream) Close(ctx context.Context) error

Close satisfies the Closer interface. The stream does not need to close any resources, as the contained client holds the connection and is responsible for closing its own resources.

func (*Stream) Read

func (s *Stream) Read() (string, error)

Read a string response from the stream cursor, reading from the buffer of previously retrieved responses when possible. When the buffer is empty, Read uses the stream's client to retrieve further responses from the database.

type Ws

type Ws struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Ws is the dialer for a WebSocket connection

func NewDialer

func NewDialer(host string, configs ...DialerConfig) (dialer *Ws)

NewDialer returns a WebSocket dialer to use when connecting to Gremlin Server

func (*Ws) IsConnected

func (ws *Ws) IsConnected() bool

IsConnected returns whether the underlying websocket is connected

func (*Ws) IsDisposed

func (ws *Ws) IsDisposed() bool

IsDisposed returns whether the underlying websocket is disposed

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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