How to use the cassandra-driver.types function in cassandra-driver

To help you get started, we’ve selected a few cassandra-driver 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 godaddy / node-priam / test / unit / driver.basic.tests.js View on Github external
it('sets default pool configuration', function () {
      // arrange
      const config = _.extend({}, getDefaultConfig());
      const configCopy = _.extend({}, config);
      const consistencyLevel = cql.types.consistencies.one;

      // act
      const instance = new Driver({ config: config });

      // assert
      assert.deepEqual(instance.poolConfig.contactPoints, configCopy.hosts, 'hosts should be passed through');
      assert.strictEqual(instance.poolConfig.keyspace, configCopy.keyspace, 'keyspace should be passed through');
      assert.strictEqual(instance.poolConfig.getAConnectionTimeout, configCopy.timeout, 'timeout should be passed through');
      assert.strictEqual(instance.poolConfig.version, configCopy.cqlVersion, 'cqlVersion should be passed through');
      assert.strictEqual(instance.poolConfig.limit, configCopy.limit, 'limit should be passed through');
      assert.strictEqual(instance.poolConfig.consistencyLevel, consistencyLevel, 'consistencyLevel should default to ONE');
    });
github strongloop / loopback-connector-cassandra / lib / cassandra.js View on Github external
ret = value;
  }
  return ret;
}

function tupleFromArray(value) {
  var ret = null;
  if (Array.isArray(value)) {
    ret = originalTupleFromArray(value);
  } else {
    ret = value;
  }
  return ret;
}

var originalFromString = cassandra.types.Uuid.fromString;
var originalTimeFromString = cassandra.types.TimeUuid.fromString;
var originalTupleFromArray = cassandra.types.Tuple.fromArray;
cassandra.types.Uuid.fromString = uuidFromString;
cassandra.types.TimeUuid.fromString = timeUuidFromString;
cassandra.types.Tuple.fromArray = tupleFromArray;

/**
 * @module loopback-connector-cassandra
 *
 * Initialize the Cassandra connector against the given data source
 *
 * @param {DataSource} dataSource The loopback-datasource-juggler dataSource
 * @param {Function} [callback] The callback function
 */
exports.initialize = function initializeDataSource(dataSource, callback) {
  dataSource.driver = cassandra; // Provide access to the native driver
github wikimedia / restbase-mod-table-cassandra / lib / db.js View on Github external
"use strict";

var P = require('bluebird');
var cass = require('cassandra-driver');
var TimeUuid = cass.types.TimeUuid;
var extend = require('extend');
var dbu = require('./dbutils');
var cassID = dbu.cassID;
var secIndexes = require('./secondaryIndexes');


function DB (client, options) {
    this.conf = options.conf;
    this.log = options.log;

    this.defaultConsistency = cass.types.consistencies[this.conf.defaultConsistency]
        || cass.types.consistencies.one;

    // cassandra client
    this.client = client;
github marley-nodejs / Learn-Nodejs-by-building-10-projects / 09_FindaDoc_Directory / routes / categories.js View on Github external
router.post('/add', function(req, res, next) {

    console.log("WE ARE HERE");

  var cat_id = cassandra.types.uuid();
  var query = "INSERT INTO findadoc.categories(cat_id, name) VALUES(?,?)";

  client.execute(query, [cat_id, req.body.name], {prepare: true},
  function(err, result){
      if(err){
          res.status(404).send({msg:err});
      } else {
          req.flash('success', "Category Added");
          res.location('/doctors');
          res.redirect('/doctors');
      }
  });
});
github masumsoft / express-cassandra / lib / orm / cassandra_types.js View on Github external
validators.is_decimal = function (obj){
    return (obj instanceof cql.types.BigDecimal);
};
github wikimedia / restbase-mod-table-cassandra / lib / dbutils.js View on Github external
'use strict';

const crypto = require('crypto');
const extend = require('extend');
const cass = require('cassandra-driver');
const P = require('bluebird');
const stableStringify = require('fast-json-stable-stringify');
const validator = require('restbase-mod-table-spec').validator;
const Long = require('cassandra-driver').types.Long;

/*
 * Various static database utility methods
 *
 * Three main sections:
 * 1) low-level helpers
 * 2) schema handling
 * 3) CQL query building
 */

const dbu = {};

/*
 * # Section 1: low-level helpers
 */
github kunalgolani / cassandra-co / src / model.js View on Github external
'use strict';

var _ = require('underskore'),
	types = require('cassandra-driver').types.dataTypes,
	composer = require('./composer');

/**
 * @param {String} table The name of the table
 * @param {CassandraCo} db The instance of CassandraCo used to create a model
 */

module.exports = function *(table, db) {

	var metadata = yield db._getTable(table),
		_columns = _.mapObject(metadata.columnsByName, ({ type }) => _.findKey(types, t => type.code === t)),
		_keys = _.pluck(metadata.partitionKeys.concat(metadata.clusteringKeys), 'name');

	/**
	 * @param {Object} data Data to initialize row instance with, column names as keys
	 */