Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-cassandra-cql

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-cassandra-cql - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

14

lib/streams.js

@@ -246,5 +246,3 @@ var util = require('util');

}
var row = [];
row.columns = meta.columns;
row.get = getCellValueByName.bind(row);
var row = new types.Row(meta.columns);
var rowOffset = reader.offset;

@@ -270,3 +268,3 @@ for(var j = 0; j < meta.columns.length; j++ ) {

{
row[j] = types.typeEncoder.decode(bytes, col.type);
row[col.name] = types.typeEncoder.decode(bytes, col.type);
bytes = null;

@@ -464,10 +462,2 @@ }

function getCellValueByName(name) {
var cellIndex = name;
if (typeof cellIndex === 'string') {
cellIndex = this.columns['_col_' + name];
}
return this[cellIndex];
}
function ParserError(err, rowIndex, colIndex) {

@@ -474,0 +464,0 @@ types.DriverError.call(this, err.message, this.constructor);

282

lib/types.js
var util = require('util');
var Int64 = require('node-int64');
var uuid = require('node-uuid');

@@ -8,24 +7,7 @@ var stream = require('stream');

var opcodes = {
error: 0x00,
startup: 0x01,
ready: 0x02,
authenticate: 0x03,
credentials: 0x04,
options: 0x05,
supported: 0x06,
query: 0x07,
result: 0x08,
prepare: 0x09,
execute: 0x0a,
register: 0x0b,
event: 0x0c,
/**
* Determines if the code is a valid opcode
*/
isInRange: function (code) {
return code > this.error && code > this.event;
}
};
//instances
/**
* Consistency levels
*/
var consistencies = {

@@ -46,2 +28,5 @@ any: 0x00,

/**
* CQL data types
*/
var dataTypes = {

@@ -84,2 +69,69 @@ custom: 0x0000,

/**
* An integer byte that distinguish the actual message from and to Cassandra
*/
var opcodes = {
error: 0x00,
startup: 0x01,
ready: 0x02,
authenticate: 0x03,
credentials: 0x04,
options: 0x05,
supported: 0x06,
query: 0x07,
result: 0x08,
prepare: 0x09,
execute: 0x0a,
register: 0x0b,
event: 0x0c,
/**
* Determines if the code is a valid opcode
*/
isInRange: function (code) {
return code > this.error && code > this.event;
}
};
/**
* Parses a string query and stringifies the parameters
*/
var queryParser = (function() {
function parse(query, args) {
if (!args || args.length === 0) {
return query;
}
var q = 0;
var a = 0;
var len = args.length;
var str = '';
try {
while (q >= 0) {
var oldq = q;
q = query.indexOf('?', q);
if (q >= 0) {
str += query.substr(oldq, q-oldq);
if (a >= len) {
throw new QueryParserError('Query parameter number ' + (a+1) + ' is not defined. Placeholder for not provided argument.');
}
str += typeEncoder.stringifyValue(args[a++]);
q += 1;
} else {
str += query.substr(oldq);
}
}
return str;
}
catch (e) {
throw new QueryParserError(e);
}
}
return {
parse: parse
};
})();
/**
* Server error codes returned by Cassandra

@@ -105,2 +157,5 @@ */

/**
* Type of result included in a response
*/
var resultKind = {

@@ -168,3 +223,3 @@ voidResult: 0x0001,

function decodeBigNumber (bytes) {
return new Int64(bytes);;
return Long.fromBuffer(bytes);
}

@@ -174,4 +229,4 @@

var value = decodeBigNumber(bytes);
if (isFinite(value)) {
return new Date(value.valueOf());
if (value.greaterThan(Long.fromNumber(Number.MIN_VALUE)) && value.lessThan(Long.fromNumber(Number.MAX_VALUE))) {
return new Date(value.toNumber());
}

@@ -300,3 +355,3 @@ return value;

}
else if(value instanceof Int64) {
else if(value instanceof Long) {
dataType = dataTypes.bigint;

@@ -378,6 +433,6 @@ }

buf = value;
} else if (value instanceof Int64) {
buf = value.buffer;
} else if (value instanceof Long) {
buf = Long.toBuffer(value);
} else if (typeof value === 'number') {
buf = new Int64(value).buffer;
buf = Long.toBuffer(Long.fromNumber(value));
}

@@ -459,3 +514,3 @@ return buf;

function stringifyValue (item) {
if (item === null) {
if (item === null || item === undefined) {
return 'NULL';

@@ -475,3 +530,3 @@ }

}
if (value === null) {
if (value === null || value === undefined) {
return 'NULL';

@@ -541,3 +596,3 @@ }

if (buf === null) {
throw new TypeError(null, value, Int64);
throw new TypeError(null, value, Long);
}

@@ -595,2 +650,4 @@ return 'blobAsBigint(' + stringifyBuffer(buf) + ')';

//classes
/**

@@ -612,2 +669,6 @@ * Represents a frame header that could be used to read from a Buffer or to write to a Buffer

/**
* The length of the header of the protocol
*/
FrameHeader.size = 8;
FrameHeader.prototype.version = 1;

@@ -632,4 +693,4 @@ FrameHeader.prototype.flags = 0x0;

};
FrameHeader.prototype.toBuffer = function () {
//TODO: Validate opcode and streamId
var buf = new Buffer(FrameHeader.size);

@@ -643,39 +704,47 @@ buf.writeUInt8(0 + this.version, 0);

};
/**
* The length of the header of the protocol
* Long constructor, wrapper of the internal library used.
*/
FrameHeader.size = 8;
var Long = require('long');
/**
* Returns a long representation.
* Used internally for deserialization
*/
Long.fromBuffer = function (value) {
if (!(value instanceof Buffer)) {
throw new TypeError('Expected Buffer', value, Buffer);
}
return new Long(value.readInt32BE(4), value.readInt32BE(0, 4));
};
/**
* Returns a big-endian buffer representation of the Long instance
* @param {Long} value
*/
Long.toBuffer = function (value) {
if (!(value instanceof Long)) {
throw new TypeError('Expected Long', value, Long);
}
var buffer = new Buffer(8);
buffer.writeUInt32BE(value.getHighBitsUnsigned(), 0);
buffer.writeUInt32BE(value.getLowBitsUnsigned(), 4);
return buffer;
};
/**
* Readable stream using to yield data from a result or a field
* Wraps a value to be included as literal in a query
*/
function ResultStream(opt) {
stream.Readable.call(this, opt);
this.buffer = [];
this.paused = true;
function QueryLiteral (value) {
this.value = value;
}
util.inherits(ResultStream, stream.Readable);
ResultStream.prototype._read = function() {
this.paused = false;
if (this.buffer.length === 0) {
this._readableState.reading = false;
}
while (!this.paused && this.buffer.length > 0) {
this.paused = this.push(this.buffer.shift());
}
QueryLiteral.prototype.toString = function () {
return this.value.toString();
};
ResultStream.prototype.add = function (chunk) {
this.buffer.push(chunk);
this.read(0);
};
/**
* Queues callbacks while the condition tests true. Similar behaviour as async.whilst.
*/
function QueueWhile(test, delayRetry)
{
function QueueWhile(test, delayRetry) {
this.queue = async.queue(function (task, queueCallback) {

@@ -705,49 +774,52 @@ async.whilst(

/**
* Wraps a value to be included as literal in a query
* Readable stream using to yield data from a result or a field
*/
function QueryLiteral (value) {
this.value = value;
function ResultStream(opt) {
stream.Readable.call(this, opt);
this.buffer = [];
this.paused = true;
}
QueryLiteral.prototype.toString = function () {
return this.value.toString();
util.inherits(ResultStream, stream.Readable);
ResultStream.prototype._read = function() {
this.paused = false;
if (this.buffer.length === 0) {
this._readableState.reading = false;
}
while (!this.paused && this.buffer.length > 0) {
this.paused = this.push(this.buffer.shift());
}
};
var queryParser = (function() {
function parse(query, args) {
if (!args || args.length === 0) {
return query;
}
ResultStream.prototype.add = function (chunk) {
this.buffer.push(chunk);
this.read(0);
};
var q = 0;
var a = 0;
var str = '';
/**
* Represents a result row
*/
function Row(columns) {
this.columns = columns;
}
try {
while (q >= 0) {
var oldq = q;
q = query.indexOf('?', q);
if (q >= 0) {
str += query.substr(oldq, q-oldq);
if (args[a] === undefined) {
throw new QueryParserError('Query parameter number ' + (a+1) + ' is not defined. Placeholder for not provided argument.');
}
str += typeEncoder.stringifyValue(args[a++]);
q += 1;
} else {
str += query.substr(oldq);
}
}
return str;
/**
* Returns the cell value.
* Created for backward compatibility: use row[columnName] instead.
* @param {String|Number} columnName Name or index of the column
*/
Row.prototype.get = function (columnName) {
if (typeof columnName === 'number') {
if (this.columns && this.columns[columnName]) {
columnName = this.columns[columnName].name;
}
catch (e) {
throw new QueryParserError(e);
else {
throw new Error('Column not found');
}
}
return this[columnName];
};
return {
parse: parse
};
})();
//error classes

@@ -767,2 +839,9 @@ /**

function QueryParserError(e) {
QueryParserError.super_.call(this, e.message, this.constructor);
this.internalError = e;
}
util.inherits(QueryParserError, DriverError);
function TimeoutError (message) {

@@ -793,21 +872,16 @@ TimeoutError.super_.call(this, message, this.constructor);

function QueryParserError(e) {
QueryParserError.super_.call(this, e.message, this.constructor);
this.internalError = e;
}
util.inherits(QueryParserError, DriverError);
exports.opcodes = opcodes;
exports.consistencies = consistencies;
exports.dataTypes = dataTypes;
exports.queryParser = queryParser;
exports.responseErrorCodes = responseErrorCodes;
exports.dataTypes = dataTypes;
exports.resultKind = resultKind;
exports.typeEncoder = typeEncoder;
exports.queryParser = queryParser;
exports.FrameHeader = FrameHeader;
exports.Long = Long;
exports.QueryLiteral = QueryLiteral;
exports.QueueWhile = QueueWhile;
exports.ResultStream = ResultStream;
exports.QueueWhile = QueueWhile;
exports.QueryLiteral = QueryLiteral;
exports.Row = Row;
exports.DriverError = DriverError;
exports.TimeoutError = TimeoutError;
{
"name": "node-cassandra-cql",
"version": "0.4.0",
"version": "0.4.1",
"description": "Node.js driver for Apache Cassandra",

@@ -13,3 +13,4 @@ "author": "Jorge Bay <jorgebaygondra@gmail.com>",

"Jan Schmidle",
"Sam Grönblom"
"Sam Grönblom",
"Daniel Smedegaard Buus"
],

@@ -31,3 +32,3 @@ "keywords": [

"async": ">= 0.2.5",
"node-int64": ">= 0.3.0",
"long": ">= 1.1.2",
"node-uuid": "1.4.0"

@@ -34,0 +35,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc