Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const url = require("url");
let myURL = url.parse(connectionString);
let auth = myURL.auth;
let splitAuth = auth.split(":");
let username = splitAuth[0];
let password = splitAuth[1];
let sslopts = myURL.protocol === "https:" ? {} : null;
// get contactPoints for the connection
let translator = new compose.ComposeAddressTranslator();
translator.setMap(mapList);
let authProvider = new cassandra.auth.PlainTextAuthProvider(username, password);
let uuid = require("uuid");
let client = new cassandra.Client({
contactPoints: translator.getContactPoints(),
policies: {
addressResolution: translator
},
authProvider: authProvider,
sslOptions: sslopts
});
// Add a word to the database
function addWord(word, definition) {
return new Promise(function(resolve, reject) {
client.execute(
"INSERT INTO grand_tour.words(my_table_id, word, definition) VALUES(?,?,?)", [uuid.v4(), word, definition], { prepare: true },
function(error, result) {
if (error) {
console.log(error);
console.error("Please pass in the stock exchange symbol file");
process.exit(1);
}
const filePath = process.argv[2];
try {
var stats = fs.statSync(filePath);
if (!stats.isFile()) {
console.error('file not exist');
process.exit(1);
}
// Read the JSON file
var stocks = JSON.parse(fs.readFileSync(filePath, "utf-8"));
var exchangeName = path.basename(filePath).split('.')[0];
//var exchangeId = '';
const client = new cassandra.Client({ contactPoints: [CASSANDRA_HOST], keyspace: CASSANDRA_KEYSPACE });
async.series([
function connect(next) {
console.log('Connecting to Cassandra');
client.connect(next);
},
/*
function getExchangeId(next) {
const query = 'SELECT exchange_id, exchange_name FROM exchange WHERE exchange_name = ?';
client.execute(query, [exchangeName], { prepare: true }, function (err, result) {
if (err) return next(err);
var row = result.first();
if (row !== null)
exchangeId = row.exchange_id;
next();
});
},
async _createConnectionPool(poolConfig, waitForConnect) {
const openRequestId = uuid.v4();
this.logger.debug('priam.Driver: Creating new pool', {
poolConfig: {
keyspace: poolConfig.keyspace,
contactPoints: poolConfig.contactPoints
}
});
const pool = new cqlDriver.Client(this._getDataStaxPoolConfig(poolConfig));
pool.storeConfig = poolConfig;
pool.waiters = [];
pool.isReady = false;
pool.on('log', (level, message, data) => {
this.emit('connectionLogged', level, message, data);
// unrecoverable errors will yield error on execution, so treat these as warnings since they'll be retried
// treat everything else as debug information.
const logMethod = (level === 'error' || level === 'warning') ? 'warn' : 'debug';
const metaData = {
datastaxLogLevel: level
};
if (typeof data === 'string') {
message += `: ${data}`;
} else {
metaData.data = data;
function createKeySpaceForTest(cb) {
var client = new cassandra.Client({ contactPoints: ['localhost'] });
var sql = 'CREATE KEYSPACE IF NOT EXISTS "' + keyspaceName +
'" WITH REPLICATION = { \'class\' : \'SimpleStrategy\',' +
' \'replication_factor\' : \'3\' }';
client.execute(sql, function(err) {
process.exit(0);
});
}
async function createClient() {
const authProvider = new cassandra.auth.PlainTextAuthProvider(databaseConfig.username, databaseConfig.password);
const config = {
contactPoints: String(databaseConfig.address).split(','),
keyspace: databaseConfig.name,
authProvider,
localDataCenter: databaseConfig.cassandraLocalDataCenter
};
let cassandraClient = new cassandra.Client(config);
return cassandraClient;
}
function connect() {
client = new cassandra.Client({ contactPoints: [CASSANDRA_HOST], keyspace: CASSANDRA_KEYSPACE });
console.log('Connecting to Cassandra');
client.connect();
}
client.connect(e=> {
if (e) {
if (e.code == 8704) {
delete conf.keyspace;
client = new cassandra.Client(conf);
if (reset) {
return drop().then(_=>order(loadCassandra)).then(_=>resolve(client));
}
return order(loadCassandra).then(_=>resolve(client));
} else {
console.error('Error connecting', e);
return reject(e);
}
}
if (reset) {
return drop().then(_=>order(loadCassandra)).then(_=>resolve(client))
} else {
resolve(client);
}
});
})
"use strict";
const cassandra = require('cassandra-driver');
const async = require('async');
const assert = require('assert');
const client = new cassandra.Client({ contactPoints: ['127.0.0.1'], localDataCenter: 'datacenter1' });
/**
* Example using async library for avoiding nested callbacks
* See https://github.com/caolan/async
* Alternately you can use the Promise-based API.
*
* Inserts a row and retrieves a row
*/
const id = cassandra.types.Uuid.random();
async.series([
function connect(next) {
client.connect(next);
},
function createKeyspace(next) {
const query = "CREATE KEYSPACE IF NOT EXISTS examples WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3' }";
_get_system_client : function(){
var connection = lodash.cloneDeep(this._connection);
delete connection.keyspace;
return new cql.Client(connection);
},