cassanknex
Advanced tools
Comparing version 1.15.0 to 1.16.0
{ | ||
"name": "cassanknex", | ||
"version": "1.15.0", | ||
"version": "1.16.0", | ||
"description": "An Apache Cassandra CQL query builder with support for the DataStax NodeJS driver, written in the spirit of Knex.", | ||
@@ -23,3 +23,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"cassandra-driver": "^3.1.5", | ||
"cassandra-driver": "^3.2.2", | ||
"inherits": "^2.0.1", | ||
@@ -26,0 +26,0 @@ "lodash": "^3.10.1" |
@@ -82,3 +82,3 @@ /** | ||
function _getAggregate(type) { | ||
return function (identifier, value) { | ||
return function (value) { | ||
@@ -88,3 +88,2 @@ var statement = { | ||
type: type, | ||
key: identifier, | ||
val: value | ||
@@ -91,0 +90,0 @@ }; |
@@ -68,4 +68,5 @@ /** | ||
var columns = [] | ||
, argArray = _.toArray(arguments); | ||
if (!argArray.length) { | ||
, argArray = _.toArray(arguments) | ||
, hasAggregates = _.has(this._grouped, "aggregate"); | ||
if (!argArray.length && !hasAggregates) { | ||
columns.push("*"); | ||
@@ -80,4 +81,8 @@ } | ||
var compiling = this.getCompiling("select", {columns: columns}) | ||
, columnStatements = _.map(compiling.value.columns, function (column) { | ||
var compiling = this.getCompiling("select", {columns: columns}); | ||
if (hasAggregates && compiling.value.columns.length === 1 && compiling.value.columns[0] === "*") { | ||
// retroactively remove "*" | ||
compiling.value.columns.length = 0; | ||
} | ||
var columnStatements = _.map(compiling.value.columns, function (column) { | ||
if (_.isObject(column)) { | ||
@@ -106,8 +111,8 @@ var key = Object.keys(column)[0]; | ||
var key, val; | ||
if (_.isObject(aggregate.key)) { | ||
key = Object.keys(aggregate.key)[0]; | ||
val = aggregate.key[key]; | ||
if (_.isObject(aggregate.val)) { | ||
key = Object.keys(aggregate.val)[0]; | ||
val = aggregate.val[key]; | ||
} | ||
else { | ||
key = aggregate.key; | ||
key = aggregate.val; | ||
} | ||
@@ -118,2 +123,15 @@ cql += (columnStatements.length ? ", " : "") + | ||
break; | ||
case "count": | ||
var key, val; | ||
if (_.isObject(aggregate.val)) { | ||
key = Object.keys(aggregate.val)[0]; | ||
val = aggregate.val[key]; | ||
} | ||
else { | ||
key = aggregate.val; | ||
} | ||
cql += (columnStatements.length ? ", " : "") + | ||
"COUNT(" + (key === "*" ? "*" : formatter.wrapQuotes(key)) + ")" + | ||
(val ? " AS " + formatter.wrapQuotes(val) : ""); | ||
break; | ||
} | ||
@@ -120,0 +138,0 @@ }); |
@@ -659,2 +659,3 @@ | ||
- ttl | ||
- count | ||
@@ -733,2 +734,5 @@ ##### <a name="QueryModifiers-ColumnFamilies"></a>*For column family queries*: | ||
- 1.16.0 | ||
- Add QueryModifier `count`, per issue [#30](https://github.com/azuqua/cassanknex/issues/30). | ||
- Update DataStax Driver module from `3.1.6` to `3.2.2`. | ||
- 1.15.0 | ||
@@ -735,0 +739,0 @@ - Add bring-your-own-driver support. |
@@ -65,4 +65,5 @@ /** | ||
"build a sample table and execute several insertions into that table, " + | ||
"and read records inserted using both the 'exec' and 'stream' and 'eachRow' methods" + | ||
" - then delete all rows from the test table.", function (done) { | ||
"read records inserted using both the 'exec' and 'stream' and 'eachRow' methods " + | ||
"and run a few aggregation queries on the records set " + | ||
"- then delete all rows from the test table.", function (done) { | ||
@@ -272,2 +273,15 @@ this.timeout(0); | ||
}, | ||
// test aggregates | ||
function (next) { | ||
var qb = cassanKnex(keyspace) | ||
.select() | ||
.count({ "*": "theCount" }) | ||
.from(columnFamily) | ||
.exec(function(err, resp) { | ||
assert(!err, err); | ||
assert.equal(rows, resp.first().theCount); | ||
next(err); | ||
}); | ||
}, | ||
// test the delete method | ||
@@ -274,0 +288,0 @@ function (next) { |
@@ -471,3 +471,3 @@ /** | ||
it.skip("should compile a simple 'count' query string", function () { | ||
it("should compile a simple 'count' query string", function () { | ||
@@ -477,3 +477,3 @@ var cql = 'SELECT COUNT(*) FROM "cassanKnexy"."columnFamily";' | ||
qb.select() | ||
.count() | ||
.count("*") | ||
.from("columnFamily"); | ||
@@ -485,2 +485,14 @@ | ||
it("should compile a 'select count as' query string", function () { | ||
var cql = 'SELECT COUNT(*) AS "theCount" FROM "cassanKnexy"."columnFamily";' | ||
, qb = cassanKnex("cassanKnexy"); | ||
qb.select() | ||
.count({"*": "theCount"}) | ||
.from("columnFamily"); | ||
var _cql = qb.cql(); | ||
assert(_cql === cql, "Expected compilation: '" + cql + "' but compiled: " + _cql); | ||
}); | ||
}); |
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
135879
3067
798
Updatedcassandra-driver@^3.2.2