How to use the gremlin.createClient function in gremlin

To help you get started, we’ve selected a few gremlin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / vscode-cosmosdb / src / graph / GraphViewServer.ts View on Github external
private async executeQuery(queryId: number, gremlinQuery: string): Promise {
    this.log(`Executing query #${queryId}: ${gremlinQuery}`);

    const client = gremlin.createClient(
      this._configuration.endpointPort,
      this._configuration.endpoint,
      {
        "session": false,
        "ssl": this._configuration.endpointPort === 443 || this._configuration.endpointPort === 8080,
        "user": `/dbs/${this._configuration.databaseName}/colls/${this._configuration.graphName}`,
        "password": this._configuration.key
      });

    // Patch up handleProtocolMessage as a temporary work-around for https://github.com/jbmusso/gremlin-javascript/issues/93
    var originalHandleProtocolMessage = client.handleProtocolMessage;
    client.handleProtocolMessage = function handleProtocolMessage(message) {
      if (!message.binary) {
        // originalHandleProtocolMessage isn't handling non-binary messages, so convert this one back to binary
        message.data = new Buffer(message.data);
        message.binary = true;
github gremlin-orm / gremlin-orm / src / gremlin-orm.js View on Github external
constructor(dialect, port, url, options) {
    // Constants
    this.DIALECTS = {AZURE: 'azure'};
    this.STRING = 'string';
    this.NUMBER = 'number';
    this.BOOLEAN = 'boolean';
    this.DATE = 'date';

    const argLength = arguments.length;
    if (argLength === 0) {
      this.client = null;
    } else if (argLength === 1) {
      this.client = Gremlin.createClient();
    } else if (argLength === 3) {
      this.client = Gremlin.createClient(port, url);
    } else {
      this.client = Gremlin.createClient(port, url, options);
    }
    if (Array.isArray(dialect)) {
      this.dialect = dialect[0];
      this.partition = dialect[1];
    }
    else {
      this.dialect = dialect;
    }
    this.definedVertices = {};
    this.definedEdges = {};
    this.vertexModel = VertexModel;
    this.edgeModel = EdgeModel;
github gremlin-orm / gremlin-orm / src / gremlin-orm.js View on Github external
constructor(dialect, port, url, options) {
    // Constants
    this.DIALECTS = {AZURE: 'azure'};
    this.STRING = 'string';
    this.NUMBER = 'number';
    this.BOOLEAN = 'boolean';
    this.DATE = 'date';

    const argLength = arguments.length;
    if (argLength === 0) {
      this.client = null;
    } else if (argLength === 1) {
      this.client = Gremlin.createClient();
    } else if (argLength === 3) {
      this.client = Gremlin.createClient(port, url);
    } else {
      this.client = Gremlin.createClient(port, url, options);
    }
    if (Array.isArray(dialect)) {
      this.dialect = dialect[0];
      this.partition = dialect[1];
    }
    else {
      this.dialect = dialect;
    }
    this.definedVertices = {};
    this.definedEdges = {};
    this.vertexModel = VertexModel;
    this.edgeModel = EdgeModel;
  }
github scorelab / EtherBeat / src / models / contract.ts View on Github external
import * as Web3 from "web3";
import * as gremlin from "gremlin";

let web3: Web3;
export default web3;

if (web3 !== undefined) {
    web3 = new Web3(Web3.currentProvider);
} else {
    // TODO - move to configuration
    web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}

const client = gremlin.createClient();
const tt = gremlin.makeTemplateTag(client);

export class Account {
    id: string;
    address: string;
    abiInterface: string;

    constructor(address: string, abiInterface?: string) {
        this.address = address;
        this.abiInterface = abiInterface;
    }

    balance() {
        const balance = web3.eth.getBalance(this.address);
        return balance.toString(10);
    }
github microsoft / SmartHotel360-SentimentAnalysis / Source / Function / AnalyzePendingTweet / index.js View on Github external
function saveToGraph(tweets) {
    console.log('Start save to Cosmos graph:');
    console.log('Establishing connection to database...');
    var configObject = {
        "session": false,
        "ssl": true,
        "user": `/dbs/${config.database}/colls/${config.collection}`,
        "password": config.primaryKey
    };

    const client = Gremlin.createClient(443, config.endpoint, configObject);
    console.log('Connection established');

    let queries = [];
    for (let tweet of tweets) { //need to check if these exist
        queries.push(constructAddVertexString('user', tweet.user));
        queries.push(constructAddVertexString('tweet', tweet.id, { text: tweet.text, sentiment: tweet.sentiment }));
        if (isIterable(tweet.hashtags)) {
            for (let hashtag of tweet.hashtags) {
                queries.push(constructAddVertexString('hashtag', hashtag));
            }
        }
        queries.push(constructAddEdgeString(
            'tweeted',
            { label: 'user', id: tweet.user },
            { label: 'tweet', id: tweet.id }
        ));
github microsoft / SmartHotel360-SentimentAnalysis / Source / Website / util / dbUtil.js View on Github external
async function setupDatabase() {
    var configObject = {
        "session": false,
        "ssl": true,
        "user": `/dbs/${config.database}/colls/${config.collection}`,
        "password": config.primarykey
    };

    const client = Gremlin.createClient(443, config.endpoint, configObject);
    let promisifiedExecute = util.promisify(client.execute.bind(client));

    async function runQueriesSerial(queries) {
        let counter = 0;
        for (let query of queries) {
            console.log("Running query " + counter++ + " of " + queries.length);
            let results;
            try {
                results = await promisifiedExecute(query, {});
            } catch (err) { //if we try to add a node that already exists, we'll get a lot of exceptions... TODO to improve
                if (!err.message.indexOf("Resource with specified id or name already exists")) {
                    console.log(err);
                }
            }
        }
    }
github bechbd / gremlin-ide / main.js View on Github external
function connectToDatabase(loginInfo) {
  console.log("connectToDatabase");
  const db = Gremlin.createClient(loginInfo.serverPort, loginInfo.serverName, { ssl: loginInfo.useSSL, user: loginInfo.userName, password: loginInfo.password, processor: loginInfo.opProcessor || ""});
  return db;
}
github bechbd / gremlin-ide / main.js View on Github external
ipc.on('query:execute', (e, query) => {
  client = Gremlin.createClient(settings.get("loginInfo.serverPort"), settings.get("loginInfo.serverName"),
    { ssl: settings.get("loginInfo.useSSL"), user: settings.get("loginInfo.userName"), password: settings.get("loginInfo.password"), processor: settings.get("loginInfo.opProcessor") || ""});
  if (client == null) {
    client = connectToDatabase();
  }

  client.execute(query, (err, results) => {
    if (err) {
      const msg = err.message;
      e.returnValue = { isError: true, error: msg };
    } else {
      e.returnValue = { isError: false, results: parseGraphson(results) };
    }
  });
})
github PommeVerte / gremlin-console-js / src / DriverClient.js View on Github external
constructor(host, port, options, parser) {
        if(typeof parser === "undefined") {
            this.parser = new Parser();
        } else {
            this.parser = parser;
        }
        this.client = GremlinDriver.createClient(port, host, options);
    }
github bradygmsft / Web-Serverless-AI-and-Graph-with-Azure-and-Visual-Studio-Code / src / function / ImageReceivedTrigger / index.js View on Github external
const createGemlinClient = (gremlinUser) => {
    return Gremlin.createClient(
        443,
        process.env.GREMLIN_ENDPOINT,
        {
            "session": false,
            "ssl": true,
            "user": gremlinUser,
            "password": process.env.COSMOSDB_KEY
        }
    );
};