cassanknex
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -61,4 +61,6 @@ /** | ||
"limit": {"name": "limit", "grouping": "limit"} | ||
"limit": {"name": "limit", "grouping": "limit"}, | ||
"allowFiltering": {"name": "allowFiltering", "grouping": "allow"} | ||
} | ||
}; |
@@ -18,3 +18,4 @@ /** | ||
"dropColumnFamily": "dropColumnFamily", | ||
"dropColumnFamilyIfExists": "dropColumnFamilyIfExists" | ||
"dropColumnFamilyIfExists": "dropColumnFamilyIfExists", | ||
"createIndex": "createIndex" | ||
}, | ||
@@ -21,0 +22,0 @@ "query": { |
{ | ||
"name": "cassanknex", | ||
"version": "1.0.0", | ||
"description": "A CLQ query builder written in the spirit of Knex.", | ||
"version": "1.1.0", | ||
"description": "A CQL query builder written in the spirit of Knex.", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/azuqua/cassanknex", |
@@ -41,2 +41,7 @@ /** | ||
break; | ||
case "allow": | ||
queryBuilder[method] = function () { | ||
return this._wrapMethod(null, methods[method].name, _getAllowFiltering(methods[method].name), arguments); | ||
}; | ||
break; | ||
} | ||
@@ -104,1 +109,9 @@ }); | ||
} | ||
function _getAllowFiltering() { | ||
return function () { | ||
this._single.allowFiltering = {grouping: "allow", allow: true}; | ||
return this; | ||
}; | ||
} |
@@ -93,2 +93,6 @@ /** | ||
} | ||
if (_.has(this._single, "allowFiltering") && this._single.allowFiltering.allow) { | ||
cql += " ALLOW FILTERING"; | ||
} | ||
this.query({ | ||
@@ -95,0 +99,0 @@ cql: cql + ";" |
@@ -15,3 +15,3 @@ | ||
A CLQ query builder written in the spirit of [Knex](knexjs.org) for [CQL 3.1.x](http://docs.datastax.com/en/cql/3.1/cql/cql_reference/cqlReferenceTOC.html). | ||
A CQL query builder written in the spirit of [Knex](knexjs.org) for [CQL 3.1.x](http://docs.datastax.com/en/cql/3.1/cql/cql_reference/cqlReferenceTOC.html). | ||
@@ -21,3 +21,3 @@ ## Why | ||
CQL was purposefully designed to be SQL-esq to enhance ease of access for those familiar w/ relational databases | ||
while Knex is the canonical NodeJS query builder for SQL dialects; however, even given the lexical similarities, the differences | ||
while Knex is the canonical NodeJS query builder for SQL dialects; however, even given the lexical similarities, the difference | ||
between the usage of CQL vs SQL is significant enough that adding CQL as yet another Knex SQL dialect does not make sense. | ||
@@ -197,2 +197,3 @@ Thus, CassanKnex. | ||
- dropColumnFamilyIfExists | ||
- createIndex | ||
@@ -254,1 +255,7 @@ #### *For keyspace queries*: | ||
- withDurableWrites | ||
### ChangeLog | ||
- 1.1.0 | ||
- Add QueryCommand `createIndex`. | ||
- Add QueryModifier `allowFiltering`. |
@@ -39,2 +39,5 @@ /** | ||
}, | ||
createIndex: function () { | ||
return this._wrapMethod(component, "createIndex", _getCreateIndex(), arguments); | ||
}, | ||
dropColumnFamily: function () { | ||
@@ -120,2 +123,29 @@ if (arguments.length === 1) { | ||
function _getCreateIndex() { | ||
return function (columnFamily, indexName, onColumn) { | ||
var compiling = this.getCompiling("createIndex", { | ||
columnFamily: columnFamily, | ||
indexName: indexName, | ||
onColumn: onColumn | ||
}); | ||
if (compiling.value.columnFamily) | ||
this._setColumnFamily(compiling.value.columnFamily); | ||
var createStatement = "CREATE INDEX" | ||
, cql = [createStatement, compiling.value.indexName, "ON"].join(" ") + | ||
" " + [this.keyspace(), this.columnFamily()].join(".") + | ||
" " + ["(", compiling.value.onColumn, ")"].join(" "); | ||
cql += ";"; | ||
this.query({ | ||
cql: cql | ||
}); | ||
return this; | ||
}; | ||
} | ||
function _getDropColumnFamily() { | ||
@@ -122,0 +152,0 @@ |
@@ -163,2 +163,14 @@ /** | ||
// CREATE INDEX | ||
it("should compile a create index statement", function () { | ||
var cql = "CREATE INDEX foo_key ON cassanKnexy.columnFamily ( foo );" | ||
, qb = cassanKnex("cassanKnexy") | ||
.createIndex("columnFamily", "foo_key", "foo"); | ||
var _cql = qb.cql(); | ||
assert(_cql === cql, "Expected compilation: '" + cql + "' but compiled: " + _cql); | ||
}); | ||
// DROP COLUMN FAMILY | ||
@@ -165,0 +177,0 @@ |
@@ -70,2 +70,13 @@ /** | ||
}); | ||
it("should compile an 'allow filtering' simple 'select' query string", function () { | ||
var cql = "SELECT id FROM cassanKnexy.columnFamily ALLOW FILTERING;" | ||
, qb = cassanKnex("cassanKnexy"); | ||
qb.select("id") | ||
.allowFiltering() | ||
.from("columnFamily"); | ||
var _cql = qb.cql(); | ||
assert(_cql === cql, "Expected compilation: '" + cql + "' but compiled: " + _cql); | ||
}); | ||
it("should compile a select query string", function () { | ||
@@ -72,0 +83,0 @@ |
68507
1728
258