New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cassanknex

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cassanknex - npm Package Compare versions

Comparing version 1.6.0 to 1.7.0

CONTRIBUTING.md

4

componentDeclarations/componentBuilderMethods.js

@@ -9,2 +9,6 @@ /**

"frozen": {"name": "frozen", "grouping": "column", jsType: "object"},
"frozenSet": {"name": "frozenSet", "grouping": "column", jsType: "object"},
"frozenMap": {"name": "frozenMap", "grouping": "column", jsType: "object"},
"frozenList": {"name": "frozenList", "grouping": "column", jsType: "object"},
"list": {"name": "list", "grouping": "column", jsType: "array"},

@@ -11,0 +15,0 @@ "set": {"name": "set", "grouping": "column", jsType: "array"},

@@ -19,3 +19,11 @@ /**

"dropColumnFamilyIfExists": "dropColumnFamilyIfExists",
"createIndex": "createIndex"
"createIndex": "createIndex",
"alterType": "alterType",
"createType": "createType",
"createTypeIfNotExists": "createTypeIfNotExists",
"dropType": "dropType",
"dropTypeIfExists": "dropTypeIfExists"
},

@@ -22,0 +30,0 @@ "query": {

2

package.json
{
"name": "cassanknex",
"version": "1.6.0",
"version": "1.7.0",
"description": "An Apache Cassandra CQL query builder with support for the DataStax NodeJS driver, written in the spirit of Knex.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -12,3 +12,3 @@

- [Why Cassanknex](#WhyCassanknex)
- [Why CassanKnex](#WhyCassanknex)
- [Usage](#Usage)

@@ -30,3 +30,3 @@ - [Generating Queries](#GeneratingQueries)

## <a name="WhyCassanknex"></a>Why
## <a name="WhyCassanknex"></a>Why (what's in a name)

@@ -437,2 +437,6 @@ CQL was purposefully designed to be SQL-esq to enhance ease of access for those familiar w/ relational databases

- createIndex
- createType
- createTypeIfNotExists
- dropType
- dropTypeIfExists

@@ -485,2 +489,5 @@ ##### <a name="QueryCommands-Keyspaces"></a>*For keyspace queries*:

- varchar
- frozen
- frozenSet
- frozenMap
- withCaching

@@ -498,4 +505,8 @@ - withCompression

- 1.7.0
- Add QueryCommands `createType`/`IfNotExists` and `dropType`/`IfExists`.
- Add QueryModifiers `frozen`/`Set`/`Map`/`List`.
- 1.7.0 features added per issue [#10](https://github.com/azuqua/cassanknex/issues/10).
- 1.6.0
- Add `options` support for `eachRow` per issue #8.
- Add `options` support for `eachRow` per issue [#8](https://github.com/azuqua/cassanknex/issues/8).
- 1.5.1, 1.5.2

@@ -502,0 +513,0 @@ - OMG DOCS!

@@ -11,3 +11,4 @@ /**

, components = require("../componentDeclarations/components")
, methods = require("../componentDeclarations/componentCompilerMethods")[components.columnFamily];
, methods = require("../componentDeclarations/componentCompilerMethods")[components.columnFamily]
, builderMethods = require("../componentDeclarations/componentBuilderMethods")[components.columnFamily];

@@ -25,2 +26,10 @@ var component = components.columnFamily;

},
createType: function () {
if (arguments.length === 1) {
arguments[1] = null; // set stand in keyspace value
}
arguments[2] = false;
arguments.length = 3;
return this._wrapMethod(component, "createType", _getCreateType(), arguments);
},
createColumnFamilyIfNotExists: function () {

@@ -34,2 +43,10 @@ if (arguments.length === 1) {

},
createTypeIfNotExists: function () {
if (arguments.length === 1) {
arguments[1] = null; // set stand in keyspace value
}
arguments[2] = true;
arguments.length = 3;
return this._wrapMethod(component, "createType", _getCreateType(), arguments);
},
alterColumnFamily: function () {

@@ -42,2 +59,10 @@ if (arguments.length === 1) {

},
alterType: function () {
if (arguments.length === 1) {
arguments[1] = null; // set stand in keyspace value
}
arguments.length = 2;
return this._wrapMethod(component, "alterType", _getAlterType(), arguments);
},
createIndex: function () {

@@ -54,2 +79,10 @@ return this._wrapMethod(component, "createIndex", _getCreateIndex(), arguments);

},
dropType: function () {
if (arguments.length === 1) {
arguments[1] = null; // set stand in keyspace value
}
arguments[2] = false;
arguments.length = 3;
return this._wrapMethod(component, "dropType", _getDropType(), arguments);
},
dropColumnFamilyIfExists: function () {

@@ -62,2 +95,10 @@ if (arguments.length === 1) {

return this._wrapMethod(component, "dropColumnFamilyIfExists", _getDropColumnFamily(), arguments);
},
dropTypeIfExists: function () {
if (arguments.length === 1) {
arguments[1] = null; // set stand in keyspace value
}
arguments[2] = true;
arguments.length = 3;
return this._wrapMethod(component, "dropTypeIfExists", _getDropType(), arguments);
}

@@ -94,4 +135,36 @@ };

};
}
function _getCreateType() {
return function (columnFamily, keyspace, ifNot) {
var compiling = this.getCompiling("createType", {
keyspace: keyspace,
columnFamily: columnFamily,
ifNot: ifNot
});
if (compiling.value.columnFamily)
this._setColumnFamily(compiling.value.columnFamily);
if (compiling.value.keyspace)
this._setKeyspace(compiling.value.keyspace);
var createStatement = compiling.value.ifNot ? "CREATE TYPE IF NOT EXISTS " : "CREATE TYPE "
, cql = createStatement + [this.keyspace(), this.columnFamily()].join(".") + " ";
cql += _compileColumns(this);
cql += _compileWith(this);
cql += ";";
this.query({
cql: cql
});
return this;
};
}
function _getAlterColumnFamily() {

@@ -129,2 +202,34 @@

function _getAlterType() {
return function (columnFamily, keyspace) {
var compiling = this.getCompiling("alterType", {
keyspace: keyspace,
columnFamily: columnFamily
});
if (compiling.value.columnFamily)
this._setColumnFamily(compiling.value.columnFamily);
if (compiling.value.keyspace)
this._setKeyspace(compiling.value.keyspace);
var alterStatement = "ALTER TYPE "
, cql = alterStatement + [this.keyspace(), this.columnFamily()].join(".") + " ";
if (_.has(this._grouped, "column")) {
cql += "ADD " + _compileColumns(this, " ADD ", false);
}
cql += _compileWith(this);
cql += _compileAlter(this);
cql += ";";
this.query({
cql: cql
});
return this;
};
}
function _getCreateIndex() {

@@ -182,4 +287,33 @@

};
}
function _getDropType() {
return function (columnFamily, keyspace, ifNot) {
var compiling = this.getCompiling("dropType", {
keyspace: keyspace,
columnFamily: columnFamily,
ifNot: ifNot
});
if (compiling.value.columnFamily)
this._setColumnFamily(compiling.value.columnFamily);
if (compiling.value.keyspace)
this._setKeyspace(compiling.value.keyspace);
var dropStatement = compiling.value.ifNot ? "DROP TYPE IF EXISTS " : "DROP TYPE "
, cql = dropStatement + [this.keyspace(), this.columnFamily()].join(".") + " ";
cql += ";";
this.query({
cql: cql
});
return this;
};
}
function _compileColumns(client, deliminator, wrap) {

@@ -209,3 +343,16 @@

case "object":
columns.push([column.name, column.type.toUpperCase(), "<" + column.options.join(",") + ">"].join(" "));
// handle the frozen set, map and list columns
if (column.type === builderMethods.frozenSet.name) {
columns.push([column.name, "SET", "<" + "FROZEN", column.options.join(",") + ">"].join(" "));
}
else if (column.type === builderMethods.frozenMap.name) {
columns.push([column.name, "MAP", "<" + column.options[0] + ", FROZEN <" + column.options[1] + ">>"].join(" "));
}
else if (column.type === builderMethods.frozenList.name) {
columns.push([column.name, "FROZEN", "<LIST", "<" + column.options[0] + ">>"].join(" "));
}
// general (non UUDT or frozen) case
else {
columns.push([column.name, column.type.toUpperCase(), "<" + column.options.join(",") + ">"].join(" "));
}
break;

@@ -212,0 +359,0 @@

@@ -80,5 +80,6 @@ /**

var cql = "CREATE COLUMNFAMILY cassanKnexy.columnFamily ( listType LIST <text>, setType SET <timestamp>, decimalType DECIMAL, booleanType BOOLEAN, blobType BLOB, timestampType TIMESTAMP, inetType INET, bigintType BIGINT, counterType COUNTER, doubleType DOUBLE, intType INT, floatType FLOAT, mapType MAP <uuid,text>, asciiType ASCII, textType TEXT, timeuuidType TIMEUUID, uuidType UUID, varcharType VARCHAR, PRIMARY KEY (uuidType) ) ;"
var cql = "CREATE COLUMNFAMILY cassanKnexy.columnFamily ( frozenList LIST <list<text>>, listType LIST <text>, setType SET <timestamp>, decimalType DECIMAL, booleanType BOOLEAN, blobType BLOB, timestampType TIMESTAMP, inetType INET, bigintType BIGINT, counterType COUNTER, doubleType DOUBLE, intType INT, floatType FLOAT, mapType MAP <uuid,text>, asciiType ASCII, textType TEXT, timeuuidType TIMEUUID, uuidType UUID, varcharType VARCHAR, PRIMARY KEY (uuidType) ) ;"
, qb = cassanKnex("cassanKnexy");
qb.createColumnFamily("columnFamily")
.list("frozenList", "list<text>")
.list("listType", "text")

@@ -107,2 +108,15 @@ .set("setType", "timestamp")

});
it("should compile a create column family statement w/ all frozen (or user defined) types", function () {
var cql = "CREATE COLUMNFAMILY cassanKnexy.columnFamily ( uudtTypeColumn FROZEN <myUUDT>, uudtTypeSetColumn SET <FROZEN myUUDT>, uudtTypeMapColumn MAP <text, FROZEN <myUUDT>>, anyTypeListColumn FROZEN <LIST <anyType>> ) ;"
, qb = cassanKnex("cassanKnexy");
qb.createColumnFamily("columnFamily")
.frozen("uudtTypeColumn", "myUUDT")
.frozenSet("uudtTypeSetColumn", "myUUDT")
.frozenMap("uudtTypeMapColumn", "text", "myUUDT")
.frozenList("anyTypeListColumn", "anyType");
var _cql = qb.cql();
assert(_cql === cql, "Expected compilation: '" + cql + "' but compiled: " + _cql);
});
it("should compile a create statement w/ compression, compaction and caching options", function () {

@@ -197,2 +211,53 @@

});
// CREATE TYPE
it("should compile a create type statement", function () {
var cql = "CREATE TYPE cassanKnexy.type ( textType TEXT ) ;"
, qb = cassanKnex("cassanKnexy")
.createType("type")
.text("textType");
var _cql = qb.cql();
assert(_cql === cql, "Expected compilation: '" + cql + "' but compiled: " + _cql);
});
it("should compile a create type if not exists statement", function () {
var cql = "CREATE TYPE IF NOT EXISTS cassanKnexy.type ( textType TEXT ) ;"
, qb = cassanKnex("cassanKnexy");
qb.createTypeIfNotExists("type")
.text("textType");
var _cql = qb.cql();
assert(_cql === cql, "Expected compilation: '" + cql + "' but compiled: " + _cql);
});
it("should compile a create type statement w/ all column types", function () {
var cql = "CREATE TYPE cassanKnexy.type ( frozenList LIST <list<text>>, listType LIST <text>, setType SET <timestamp>, decimalType DECIMAL, booleanType BOOLEAN, blobType BLOB, timestampType TIMESTAMP, inetType INET, bigintType BIGINT, counterType COUNTER, doubleType DOUBLE, intType INT, floatType FLOAT, mapType MAP <uuid,text>, asciiType ASCII, textType TEXT, timeuuidType TIMEUUID, uuidType UUID, varcharType VARCHAR ) ;"
, qb = cassanKnex("cassanKnexy");
qb.createType("type")
.list("frozenList", "list<text>")
.list("listType", "text")
.set("setType", "timestamp")
.decimal("decimalType")
.boolean("booleanType")
.blob("blobType")
.timestamp("timestampType")
.inet("inetType")
.bigint("bigintType")
.counter("counterType")
.double("doubleType")
.int("intType")
.float("floatType")
.map("mapType", "uuid", "text")
.ascii("asciiType")
.text("textType")
.timeuuid("timeuuidType")
.uuid("uuidType")
.varchar("varcharType");
var _cql = qb.cql();
assert(_cql === cql, "Expected compilation: '" + cql + "' but compiled: " + _cql);
});
});

@@ -64,2 +64,11 @@ /**

},
// test create uudt
function (next) {
var qb = cassanKnex(keyspace)
.createTypeIfNotExists("typy")
.list("keys", "text")
.uuid("rando")
.int("dec")
.exec(next);
},
// test create column family

@@ -73,2 +82,3 @@ function (next) {

.text("data")
.frozen("written", "typy")
.primary("id", "timestamp")

@@ -81,3 +91,4 @@ .exec(next);

var items = _.map(Array(rows), function () {
return {id: uuid.v4(), timestamp: new Date(), data: ""};
var id = uuid.v4();
return {id: id, timestamp: new Date(), data: "", written: {keys: ["foo", "bar"], rando: id, dec: 42}};
});

@@ -90,3 +101,3 @@

.into(columnFamily)
.exec(done);
.exec({prepare: true}, done);
}, next);

@@ -93,0 +104,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc