Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added support for column count [ closes #26 ]

  • Loading branch information...
commit d87f664e584aba07e09ed707189e306b104f58f8 1 parent ff3e10b
@devdazed devdazed authored
Showing with 45 additions and 3 deletions.
  1. +2 −1  History.md
  2. +32 −2 lib/column_family.js
  3. +11 −0 test/thrift.js
View
3  History.md
@@ -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 ]
View
34 lib/column_family.js
@@ -288,6 +288,31 @@ ColumnFamily.prototype.remove = function() {
};
/**
+ * 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
* @param {Object} options Options for the get, can have start, end, max, consistencyLevel
@@ -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);
};
View
11 test/thrift.js
@@ -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'),
Please sign in to comment.
Something went wrong with that request. Please try again.