DriverClient

class
 new DriverClient() 

Option name Type Description

This is a client class that connects to gremlin-server directly

class DriverClient {
Option name Type Description
_client;
Option name Type Description
parser;

constructor

constructor
 constructor() 

Option name Type Description
host String

the host name / ip

port Integer

the port number for the client to connect to

options Object

the driver options as per defined in the driver documentation

return

void

Create the client

constructor(host, port, options, parser) {
    if(typeof parser === "undefined") {
        this.parser = new Parser();
    } else {
        this.parser = parser;
    }
    this._client = GremlinDriver.createClient(port, host, options);
}

execute

method
 execute() 

Option name Type Description
query String

mandatory: the gremlin query to run

bindings Object

optional: the bindings associated to this query

callback Function

optional: function that executes once the results are received.

return Void

Run a query with various params.
Bellow are the three expected params. optionals can be ommitted and interchanged

execute(query, bindings, callback) {
    if(typeof bindings === 'function') {
        callback = bindings;
        bindings = {};
    }

    //customize the callback params to use Parser
    const customCallback = (err, results) => {
        callback(this.parser.create(err, results));
    };
    this._client.execute(query, bindings, customCallback);
}

onError

method
 onError() 

Option name Type Description
callback Function

the method to run on client error.

return Void

Register a callback on error
It's rare to need this but sometimes you'll want to register a sepcific behavior against the client's error management

onError(callback) {
    this._client.on('error', callback);
}

onOpen

method
 onOpen() 

Option name Type Description
callback Function

the method to run on client error.

return Void

Register a callback on Open

onOpen(callback) {
    this._client.on('open', callback);
}
}

export default DriverClient;