videolabs/gremlin

Name: gremlin

Owner: Videolabs

Description: Go graph database client for TinkerPop3 Gremlin Server

Forked from: go-gremlin/gremlin

Created: 2016-12-16 14:09:52.0

Updated: 2016-12-16 14:09:53.0

Pushed: 2016-12-20 09:41:39.0

Homepage: null

Size: 14

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Gremlin Server Client for Go

This library will allow you to connect to any graph database that supports TinkerPop3 using Go. This includes databases like Titan and Neo4J. TinkerPop3 uses Gremlin Server to communicate with clients using either WebSockets or REST API. This library talks to Gremlin Server using WebSockets.

Installation

et github.com/go-gremlin/gremlin

Usage

Export the list of databases you want to connect to as GREMLIN_SERVERS like so:-

rt GREMLIN_SERVERS="ws://server1:8182, ws://server2:8182"

Import the library eg import "github.com/go-gremlin/gremlin".

Parse and save your cluster of services. You only need to do this once before submitting any queries (Perhaps in main()):-

if err := gremlin.NewCluster(); err != nil {
    // handle error here
}

Instead of using an environment variable, you can also pass the servers directly to NewCluster(). This is more convenient in development. For example:-

if err := gremlin.NewCluster("ws://dev.local:8182", "ws://staging.local:8182"); err != nil {
    // handle error
}

To actually run queries against the database, make sure the package is imported and issue a gremlin query like this:-

data, err := gremlin.Query(`g.V()`).Exec()
if err != nil  {
    // handle error
}

data is a JSON array in bytes []byte if any data is returned otherwise it is nil. For example you can print it using:-

fmt.Println(string(data))

or unmarshal it as desired.

You can also execute a query with bindings like this:-

data, err := gremlin.Query(`g.V().has("name", userName).valueMap()`).Bindings(gremlin.Bind{"userName": "john"}).Exec()

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.