Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
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;
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;
}
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);
}
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 }
));
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);
}
}
}
}
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;
}
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) };
}
});
})
constructor(host, port, options, parser) {
if(typeof parser === "undefined") {
this.parser = new Parser();
} else {
this.parser = parser;
}
this.client = GremlinDriver.createClient(port, host, options);
}
const createGemlinClient = (gremlinUser) => {
return Gremlin.createClient(
443,
process.env.GREMLIN_ENDPOINT,
{
"session": false,
"ssl": true,
"user": gremlinUser,
"password": process.env.COSMOSDB_KEY
}
);
};