Skip to content
This repository has been archived by the owner on Feb 22, 2019. It is now read-only.

Commit

Permalink
added support for column count [ closes #26 ]
Browse files Browse the repository at this point in the history
  • Loading branch information
devdazed committed Oct 19, 2012
1 parent ff3e10b commit d87f664
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
3 changes: 2 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
==================

* Fixed issue with composite column meta column marshalling [ @devdazed ]
* Exposed setColumnValidator to the user [ @devdazed #
* Exposed setColumnValidator to the user [ @devdazed #3 ]
* Added support for column counts to Thrift API [ @devdazed #26 ]


34 changes: 32 additions & 2 deletions lib/column_family.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,31 @@ ColumnFamily.prototype.remove = function() {
this.connection.execute('remove', marshalledKey, path, timestamp * 1000, consistency, args.callback);
};

/**
* Counts the number of columns in a row by it's key
* @param {String} key The key to get
* @param {Object} options Options for the get, can have start, end, max, consistencyLevel
* <ul>
* <li>
* start: the from part of the column name, for composites pass an array. By default the
* composite queries are inclusive, to make them exclusive pass an array of arrays where the
* inner array is [ value, false ].
* </li>
* start: the end part of the column name, for composites pass an array. By default the
* composite queries are inclusive, to make them exclusive pass an array of arrays where the
* inner array is [ value, false ].
* <li>reversed: {Boolean} to whether the range is reversed or not</li>
* <li>max: the max amount of columns to return</li>
* <li>columns: an {Array} of column names to get</li>
* <li>consistencyLevel: the read consistency level</li>
* </ul>
* @param {Function} callback The callback to invoke once the response has been received
*/
ColumnFamily.prototype.count = function(key, options, callback){
options.count = true;
this.get(key, options, callback);
};

/**
* Get a row by its key
* @param {String} key The key to get
Expand Down Expand Up @@ -329,10 +354,15 @@ ColumnFamily.prototype.get = function(key, options, callback){
return;
}

callback(null, Row.fromThrift(key, val, self));
if(options.count === true){
callback(null, val);
} else {
callback(null, Row.fromThrift(key, val, self));
}
}

this.connection.execute('get_slice', marshalledKey, columnParent(self), predicate, consistency, onComplete);
var command = options.count === true ? 'get_count' : 'get_slice';
this.connection.execute(command, marshalledKey, columnParent(self), predicate, consistency, onComplete);
};


Expand Down
11 changes: 11 additions & 0 deletions test/thrift.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ module.exports = {
});
},

'test standard cf.get count':function(test, assert){
cf_standard.count(config.standard_row_key, config.standard_get_options, function(err, val){
assert.ifError(err);
assert.ok(typeof val === 'number');
assert.ok(val === 1);

test.finish();
});
},


'test standard cf with composite column slice':function(test, assert){
var values = [
new Helenus.Column([1, new Date(1)], 'a'),
Expand Down

0 comments on commit d87f664

Please sign in to comment.