Documentation
¶
Overview ¶
Package grammes is an API/Wrapper for the Gremlin traversal language to interact with graph databases. It includes various levels of functionality to add, remove, and change vertices and edges in the database. Usage of higher level API is shown in various examples in the `examples/` directory with full documentation.
To get started with this package you may begin by making a Grammes client using either the Dial function or the DialWithWebSocket function. With this client you may begin interacting with your graph database with the client's multitude of function options. To narrow down what you want to do it may be easier to choose one of the `client.Querier` options.
What this example does is create a new Grammes Client using the DialWithWebSocket function. With this client it executes a simple string query that just does some simple addition. Then it will return the raw result out.
For further customizability you may check out packages within the `query/` directory.
To see examples on how to use this package further then check out the `examples/` directory.
Example (ExecuteQuery) ¶
package main import ( "log" "github.com/00security/grammes" ) func main() { // Creates a new client with the localhost IP. client, err := grammes.DialWithWebSocket("ws://127.0.0.1:8182") if err != nil { log.Fatalf("Error while creating client: %s\n", err.Error()) } // Create a graph traversal to use when querying. g := grammes.Traversal() // Executing a basic query to add a vertex to the graph // with label "testingVertex" and property "name" that equals "damien" res, err := client.ExecuteQuery(g.AddV("testingVertex").Property("name", "damien")) if err != nil { log.Fatalf("Querying error: %s\n", err.Error()) } // Print out the result as a string for _, r := range res { log.Println(string(r)) } }
Output:
Example (ExecuteStringQuery) ¶
package main import ( "log" "github.com/00security/grammes" ) func main() { // Creates a new client with the localhost IP. client, err := grammes.DialWithWebSocket("ws://127.0.0.1:8182") if err != nil { log.Fatalf("Error while creating client: %s\n", err.Error()) } // Executing a basic query to assure that the client is working. res, err := client.ExecuteStringQuery("1+3") if err != nil { log.Fatalf("Querying error: %s\n", err.Error()) } // Print out the result as a string for _, r := range res { log.Println(string(r)) } }
Output:
Example (NewClient) ¶
package main import ( "log" "github.com/00security/grammes" ) func main() { // Creates a new client with the localhost IP. client, err := grammes.DialWithWebSocket("ws://127.0.0.1:8182") if err != nil { log.Fatalf("Error while creating client: %s\n", err.Error()) } _ = client }
Output:
Index ¶
- Variables
- func CustomTraversal(q string) traversal.String
- func Traversal() traversal.String
- func VerboseTraversal() graph.String
- type APIData
- type Client
- func (c *Client) Address() string
- func (c *Client) Auth() (*gremconnect.Auth, error)
- func (c *Client) Close()
- func (c *Client) Connect() error
- func (c *Client) IsBroken() bool
- func (c *Client) IsConnected() bool
- func (c *Client) Redial(dialer gremconnect.Dialer) error
- func (c *Client) SetLogger(newLogger logging.Logger)
- type ClientConfiguration
- func WithAuthUserPass(user, pass string) ClientConfiguration
- func WithCompression(enableCompression bool) ClientConfiguration
- func WithErrorChannel(err chan error) ClientConfiguration
- func WithGremlinVersion(versionNumber int) ClientConfiguration
- func WithHTTPAuth(provider gremconnect.AuthProvider) ClientConfiguration
- func WithHandshakeTimeout(handshakeTimeout time.Duration) ClientConfiguration
- func WithLogger(newLogger logging.Logger) ClientConfiguration
- func WithMaxConcurrentMessages(limit int) ClientConfiguration
- func WithMaxConcurrentRequests(limit int) ClientConfiguration
- func WithPingInterval(interval time.Duration) ClientConfiguration
- func WithReadBufferSize(readBufferSize int) ClientConfiguration
- func WithReadingWait(interval time.Duration) ClientConfiguration
- func WithRequestTimeout(interval time.Duration) ClientConfiguration
- func WithTLS(conf *tls.Config) ClientConfiguration
- func WithTimeout(interval time.Duration) ClientConfiguration
- func WithWriteBufferResizing(writeBufferResizing bool) ClientConfiguration
- func WithWriteBufferSize(writeBufferSize int) ClientConfiguration
- func WithWritingWait(interval time.Duration) ClientConfiguration
- type Data
- type Edge
- type EdgeList
- type IDList
- type Property
- type PropertyList
- type PropertyMap
- type PropertyValue
- type SimpleValue
- type Vertex
- type VertexList
- type VertexValue
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // NewWebSocketDialer returns websocket with established connection. NewWebSocketDialer = gremconnect.NewWebSocketDialer // NewVertex returns a vertex struct meant for adding it. NewVertex = model.NewVertex // NewProperty returns a property struct meant for adding it to a vertex. NewProperty = model.NewProperty // UnmarshalEdgeList is a utility to unmarshal a list // or array of edges properly. UnmarshalEdgeList = model.UnmarshalEdgeList // UnmarshalVertexList is a utility to unmarshal a list // or array of vertices properly. UnmarshalVertexList = model.UnmarshalVertexList // UnmarshalPropertyList is a utility to unmarshal a list // or array of IDs properly. UnmarshalPropertyList = model.UnmarshalPropertyList )
Functions ¶
func CustomTraversal ¶
CustomTraversal could be used when you need to specifically need to change some property of the traversal. This can be something such as:
// ==> graph.traversal().withoutStrategies(LazyBarrierStrategy)
func VerboseTraversal ¶
VerboseTraversal will return a new graph traversal string ready to use when executing a query.
Types ¶
type APIData ¶
APIData is used to get quick access to the model.APIData without having to import it everywhere in the grammes package.
APIData holds the request in which you can make a query with using the Grammes library.
type Client ¶
type Client struct { // GraphManager is an interface used to have query functions that // handle all interactions to the graph database. manager.GraphManager // contains filtered or unexported fields }
Client is used to handle the graph, schema, connection, and basic debug logging when querying the graph database. When handling more than one queries to the graph database, it is better to use a client rather than the quick package.
func Dial ¶
func Dial(conn gremconnect.Dialer, cfgs ...ClientConfiguration) (*Client, error)
Dial returns a working client with the given dialer and configurations.
func DialWithWebSocket ¶
func DialWithWebSocket(host string, cfgs ...ClientConfiguration) (*Client, error)
DialWithWebSocket returns a new client with a websocket dialer and possible client configurations.
func (*Client) Auth ¶
func (c *Client) Auth() (*gremconnect.Auth, error)
Auth will get the authentication user and pass from the dialer.
func (*Client) Connect ¶
Connect will connect to the configured host address. If this is reconnecting then make sure that your errs channel has a new handler function set up, because it won't set up automatically.
func (*Client) IsConnected ¶
IsConnected returns if the client currently has an established connection to any servers.
type ClientConfiguration ¶
type ClientConfiguration func(*Client)
ClientConfiguration is the type used for configuring and changing values in the client and the dialer.
func WithAuthUserPass ¶
func WithAuthUserPass(user, pass string) ClientConfiguration
WithAuthUserPass sets the authentication credentials within the dialer. (This includes the username and password)
func WithCompression ¶ added in v1.3.3
func WithCompression(enableCompression bool) ClientConfiguration
WithCompression sets the compression flag for websocket connections
func WithErrorChannel ¶
func WithErrorChannel(err chan error) ClientConfiguration
WithErrorChannel will assign an error channel to send connection errors through for the user to handle.
func WithGremlinVersion ¶
func WithGremlinVersion(versionNumber int) ClientConfiguration
WithGremlinVersion sets the version of the gremlin traversal language being used by the client.
func WithHTTPAuth ¶ added in v1.3.3
func WithHTTPAuth(provider gremconnect.AuthProvider) ClientConfiguration
WithHTTPAuth sets the authentication provider within the dialer
func WithHandshakeTimeout ¶ added in v1.3.3
func WithHandshakeTimeout(handshakeTimeout time.Duration) ClientConfiguration
WithHandshakeTimeout sets the websocket handshake timeout
func WithLogger ¶
func WithLogger(newLogger logging.Logger) ClientConfiguration
WithLogger will replace the default zap.Logger with a custom logger that implements the logging.Logger interface.
func WithMaxConcurrentMessages ¶
func WithMaxConcurrentMessages(limit int) ClientConfiguration
WithMaxConcurrentMessages sets the limit as to how many requests can be stored in the requests buffer.
func WithMaxConcurrentRequests ¶ added in v1.3.3
func WithMaxConcurrentRequests(limit int) ClientConfiguration
WithMaxConcurrentRequests sets the limit as to how many requests can done simultaneously.
func WithPingInterval ¶
func WithPingInterval(interval time.Duration) ClientConfiguration
WithPingInterval sets the interval of ping sending for know is connection is alive and in consequence the client is connected.
func WithReadBufferSize ¶ added in v1.3.3
func WithReadBufferSize(readBufferSize int) ClientConfiguration
WithReadBufferSize sets the max read buffer size for the websocket frame
func WithReadingWait ¶
func WithReadingWait(interval time.Duration) ClientConfiguration
WithReadingWait sets the time to wait when reading with the dialer in seconds.
func WithRequestTimeout ¶ added in v1.3.3
func WithRequestTimeout(interval time.Duration) ClientConfiguration
WithRequestTimeout sets the timeout when reading a request from the gremlin server
func WithTimeout ¶
func WithTimeout(interval time.Duration) ClientConfiguration
WithTimeout sets the timeout to wait when dialing with the dialer in seconds.
func WithWriteBufferResizing ¶ added in v1.3.3
func WithWriteBufferResizing(writeBufferResizing bool) ClientConfiguration
WithWriteBufferResizing enables dynamic write buffer expansion, effectively disabling websocket frame fragmentation (which TinkerPop doesn't support)
func WithWriteBufferSize ¶ added in v1.3.3
func WithWriteBufferSize(writeBufferSize int) ClientConfiguration
WithWriteBufferSize sets the max write buffer size for the websocket frame
func WithWritingWait ¶
func WithWritingWait(interval time.Duration) ClientConfiguration
WithWritingWait sets the time to wait when writing with the dialer in seconds.
type Data ¶
Data is used to get quick access to the model.Data without having to import it everywhere in the grammes package.
Data holds basic information such as the label, name, ID, and properties of what this is being associated with.
type Edge ¶
Edge is used to get quick access to the model.Edge without having to import it everywhere in the grammes package.
Tinkerpop: http://tinkerpop.apache.org/javadocs/3.2.1/core/org/apache/tinkerpop/gremlin/structure/Edge.html
outVertex ---label---> inVertex.
Edge is the object that builds a connection between two or more vertices.
type EdgeList ¶
EdgeList is used to get quick access to the model.EdgeList without having to import it everywhere in the grammes package.
type IDList ¶
IDList is used to get quick access to the model.IDList without having to import it everywhere in the grammes package.
type Property ¶
Property is used to get quick access to the model.Property without having to import it everywhere in the grammes package.
Property holds the type and value of the property. It's extra information used by PropertyDetail.
type PropertyList ¶
type PropertyList = model.PropertyList
PropertyList is used to get quick access to the model.PropertyList without having to import it everywhere in the grammes package.
type PropertyMap ¶
type PropertyMap = model.PropertyMap
PropertyMap is used to get quick access to the model.PropertyMap without having to import it everywhere in the grammes package.
Tinkerpop: http://tinkerpop.apache.org/javadocs/3.2.1/core/org/apache/tinkerpop/gremlin/structure/Property.html
PropertyMap is the map used to hold the properties itself. the string key is equivalent to the Gremlin key and the []Property is the value. Properties can have multiple values; this is why we must have it as a slice of Property.
type PropertyValue ¶
type PropertyValue = model.PropertyValue
PropertyValue is used to get quick access to the model.PropertyValue without having to import it everywhere in the grammes package.
PropertyValue contains the ID, value, and label of this property's value.
type SimpleValue ¶
type SimpleValue = model.SimpleValue
SimpleValue is used to get quick access to the model.SimpleValue without having to import it everywhere in the grammes package.
SimpleValue is used to unmarshal simple value responses from the TinkerPop server. These can include simple datatypes like Int, String, Double, Bool, etc.
type Vertex ¶
Vertex is used to get quick access to the model.Vertex without having to import it everywhere in the grammes package.
TinkerPop: http://tinkerpop.apache.org/javadocs/3.2.1/core/org/apache/tinkerpop/gremlin/structure/Vertex.html
---inEdges---> vertex ---outEdges--->.
Vertex maintains pointers to both a set of incoming and outgoing Edge objects. The outgoing edges are the edges for which the Vertex is a tail. The incoming edges are those edges for which the Vertex is the head.
type VertexList ¶
type VertexList = model.VertexList
VertexList is used to get quick access to the model.VertexList without having to import it everywhere in the grammes package.
type VertexValue ¶
type VertexValue = model.VertexValue
VertexValue is used to get quick access to the model.VertexValue without having to import it everywhere in the grammes package.
VertexValue contains the 'value' data from the Vertex object.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
Package gremconnect has the connection related structs and functions.
|
Package gremconnect has the connection related structs and functions. |
Package gremerror holds custom error types to return in the Grammes package.
|
Package gremerror holds custom error types to return in the Grammes package. |
Package logging provides some zap loggers for the use of a Grammes client.
|
Package logging provides some zap loggers for the use of a Grammes client. |
Package manager contains the graph managers to query the database.
|
Package manager contains the graph managers to query the database. |
Package model holds structs of the Gremlin counterparts and related methods.
|
Package model holds structs of the Gremlin counterparts and related methods. |
Package query contains the interface used to define a graph database query.
|
Package query contains the interface used to define a graph database query. |
cardinality
Package cardinality contains the object that describes number of relationship occurrences for objects.
|
Package cardinality contains the object that describes number of relationship occurrences for objects. |
column
Package column contains the object to reference particular parts of a column.
|
Package column contains the object to reference particular parts of a column. |
consumer
Package consumer contains the object to control how barriers emit their values.
|
Package consumer contains the object to control how barriers emit their values. |
datatype
Package datatype contains the object to represent Datatypes in Gremlin.
|
Package datatype contains the object to represent Datatypes in Gremlin. |
direction
Package direction contains the object to denote the direction of an edge.
|
Package direction contains the object to denote the direction of an edge. |
graph
Package graph contains a verbose graph traversal.
|
Package graph contains a verbose graph traversal. |
multiplicity
Package multiplicity contains the object to control property sets for an edge.
|
Package multiplicity contains the object to control property sets for an edge. |
operator
Package operator contains the object to apply mathematical operations to a graph traversal.
|
Package operator contains the object to apply mathematical operations to a graph traversal. |
pop
Package pop contains the object that determines the gathered values.
|
Package pop contains the object that determines the gathered values. |
predicate
Package predicate contains the object to control the searching predicates of a graph traversal.
|
Package predicate contains the object to control the searching predicates of a graph traversal. |
scope
Package scope contains the Scope object to control relations of a graph traversal.
|
Package scope contains the Scope object to control relations of a graph traversal. |
token
Package token contains the object to define parts of a vertex.
|
Package token contains the object to define parts of a vertex. |
traversal
Package traversal contains the struct for a graph traversal and its steps.
|
Package traversal contains the struct for a graph traversal and its steps. |
Package quick is used for when you want to execute queries to the graph database without having to use a Grammes client.
|
Package quick is used for when you want to execute queries to the graph database without having to use a Grammes client. |