Comparing version 0.5.3 to 0.5.4
var util = require('util'), | ||
Marshal = require('./marshal'), | ||
Column = require('./column'), | ||
CounterColumn = require('./counter_column'), | ||
Row = require('./row'), | ||
@@ -115,2 +116,3 @@ ttype = require('./cassandra/cassandra_types'); | ||
* @param {Object} columns | ||
* @param {Object} options | ||
* @private | ||
@@ -120,3 +122,3 @@ * @memberOf ColumnFamily | ||
*/ | ||
function getColumns(columns){ | ||
function getColumns(columns, options){ | ||
var keys = Object.keys(columns), len = keys.length, i = 0, key, value, arr = [], | ||
@@ -133,3 +135,3 @@ ts = new Date(); | ||
arr.push(new Column(key, value, ts)); | ||
arr.push(new Column(key, value, ts, options.ttl)); | ||
} | ||
@@ -175,2 +177,3 @@ return arr; | ||
this.isSuper = definition.column_type === 'Super'; | ||
this.isCounter = definition.default_validation_class === 'org.apache.cassandra.db.marshal.CounterColumnType'; | ||
this.keyspace = keyspace; | ||
@@ -212,3 +215,3 @@ this.connection = keyspace.connection; | ||
if(!Array.isArray(columns)){ | ||
columns = getColumns(columns); | ||
columns = getColumns(columns, options); | ||
} | ||
@@ -388,2 +391,49 @@ | ||
/** | ||
* Increments a counter column. | ||
* @param {Object} key Row key | ||
* @param {Object} column Column name | ||
* @param {Number} value Integer to increase by, defaults to 1 (optional) | ||
* @param {Object} options The thrift options (optional) | ||
* @param {Function} callback The callback to call once complete | ||
*/ | ||
ColumnFamily.prototype.incr = function (key, column, value, options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
if (typeof value === 'function') { | ||
callback = value; | ||
options = {}; | ||
value = 1; | ||
} | ||
if (typeof value === 'object') { | ||
options = value; | ||
value = 1; | ||
} | ||
var mutations = [], batch = {}, col, | ||
consistency = options.consistency || options.consistencyLevel || DEFAULT_WRITE_CONSISTENCY; | ||
col = new CounterColumn(column, value); | ||
mutations.push(new ttype.Mutation({ | ||
column_or_supercolumn: new ttype.ColumnOrSuperColumn({ | ||
counter_column: col.toThrift(this.columnMarshaller) | ||
}) | ||
})); | ||
var marshalledKey = this.keyMarshaller.serialize(key).toString('binary'); | ||
batch[marshalledKey] = {}; | ||
batch[marshalledKey][this.definition.name] = mutations; | ||
this.connection.execute('batch_mutate', batch, consistency, callback); | ||
}; | ||
module.exports = ColumnFamily; |
@@ -438,3 +438,3 @@ | ||
callback(null, res.num); | ||
} if (res.type === ttype.CqlResultType.VOID) { | ||
} else if (res.type === ttype.CqlResultType.VOID) { | ||
callback(null); | ||
@@ -441,0 +441,0 @@ } |
@@ -57,2 +57,9 @@ | ||
/** | ||
* The CounterColumn | ||
* @static | ||
* @see CounterColumn | ||
*/ | ||
Helenus.CounterColumn = require('./counter_column'); | ||
/** | ||
* The Row | ||
@@ -59,0 +66,0 @@ * @static |
@@ -13,2 +13,9 @@ var Serializers = require('./serializers'), | ||
/** | ||
* Returns the same value | ||
* @private | ||
* @memberOf Marshal | ||
*/ | ||
var IDENTITY = function (val) { return val; }; | ||
/** | ||
* Supported types for marshalling | ||
@@ -27,3 +34,3 @@ * @private | ||
'TimeUUIDType': { ser:Serializers.encodeTimeUUID, de:Deserializers.decodeTimeUUID }, | ||
'CounterColumnType': { ser:NOOP, de:NOOP }, | ||
'CounterColumnType': { ser:IDENTITY, de:IDENTITY }, | ||
'FloatType': { ser:Serializers.encodeFloat, de:Deserializers.decodeFloat }, | ||
@@ -30,0 +37,0 @@ 'DoubleType':{ ser:Serializers.encodeDouble, de:Deserializers.decodeDouble }, |
@@ -65,8 +65,9 @@ var util = require('util'), | ||
Row.fromThrift = function(key, columns, cf){ | ||
var data = { columns: [], key:key }, | ||
var data = { columns: [], key:key }, col, | ||
schema = {}, i = 0, len = columns.length; | ||
//TODO: Implement counter and super columns | ||
//TODO: Implement super columns | ||
for(; i < len; i += 1){ | ||
data.columns.push( columns[i].column ); | ||
col = cf.isCounter ? columns[i].counter_column : columns[i].column; | ||
data.columns.push( col ); | ||
} | ||
@@ -73,0 +74,0 @@ |
{ | ||
"name": "helenus" | ||
, "version": "0.5.3" | ||
, "version": "0.5.4" | ||
, "description": "NodeJS Bindings for Cassandra" | ||
@@ -26,3 +26,3 @@ , "keywords": ["cassandra"] | ||
, "main": "index" | ||
, "engines": { "node": "0.6.x | 0.7.x" } | ||
, "engines": { "node": ">=0.6.0 <0.9.0" } | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
576617
39
13288