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

cassanknex

Package Overview
Dependencies
Maintainers
2
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.14.0 to 1.15.0

24

index.js

@@ -102,6 +102,22 @@ /**

if (config && config.connection) {
cassandra = new cassandraDriver.Client(config.connection);
cassandra.connect(function (err) {
cassanKnex.emit("ready", err);
});
if (config.connection.contactPoints) {
// initialize a new driver using included lib
cassandra = new cassandraDriver.Client(config.connection);
cassandra.connect(function (err) {
cassanKnex.emit("ready", err);
});
}
else if (config.connection.connected) {
// assume it's an initialized driver
cassandra = config.connection;
process.nextTick(function () {
cassanKnex.emit("ready");
});
}
else {
// oops
process.nextTick(function () {
cassanKnex.emit("ready", new Error("Client initialization requires either connection arguments or an initialized cassandra driver."));
});
}
}

@@ -108,0 +124,0 @@

2

package.json
{
"name": "cassanknex",
"version": "1.14.0",
"version": "1.15.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",

@@ -8,3 +8,3 @@

A [fully tested][travis-url] Apache Cassandra CQL query builder with support for the DataStax NodeJS driver, written in the spirit of [Knex][knexjs-url] for [CQL 3.x][cassandra-cql-3_1-ref-url].
A [fully tested][travis-url] Apache Cassandra CQL query builder with support for the [DataStax NodeJS driver][cassandra-driver-url], written in the spirit of [Knex][knexjs-url] for [CQL 3.x][cassandra-cql-3_1-ref-url].

@@ -23,2 +23,3 @@ ## Installation

- [Executing Queries](#ExecutingQueries)
- [Bring Your Own Driver](#BYOD)
- [Quick Start](#Quickstart)

@@ -58,3 +59,3 @@ - [Debugging Queries](#Debugging)

```js
var cassanKnex = require("cassanknex")();
var cassanKnex = require("cassanknex")(<DRIVER_OPTIONS|undefined>);
var qb = cassanKnex(KEYSPACE).QUERY_COMMAND()

@@ -72,2 +73,10 @@ .QUERY_MODIFIER_1()

`<DRIVER_OPTIONS>` may be provided to configure the client, and is an object w/ the following optional fields:
- `connection`: `<InitializedDatastaxDriverInstance>` or `<DatastaxConnectionArguments>`
The client will use an initialized datastax driver instance if provied (either the [Cassandra driver][cassandra-driver-url] or [DSE driver][dse-driver-url] will work).
Alternatively, you can provide arguments that will be forwarded to the underlying Cassandra driver instance.
- `debug`: `boolean`
Toggle debug logs (see [debugging](#Debugging)).
### <a name="ExecutingQueries"></a>As a query executor

@@ -79,2 +88,4 @@

You may provide your own driver or use the included DataStax driver.
```js

@@ -154,2 +165,58 @@ var cassanKnex = require("cassanknex")({

#### <a name="BYOD"></a>Bring your own Driver
While the package includes the vanilla [Cassandra driver][cassandra-driver-url] (supported by Datastax),
and will use that driver to connect to your cluster if you provide a connection configuration, you may optionally provide your own initialized driver to the `cassaknex` constructor.
This allows for using either the [DSE driver][dse-driver-url] or a different version of the Cassandra driver, per your applications needs.
e.g., w/ the built in `cassandra-driver`:
```js
var cassanKnex = require("cassanknex")({
connection: { // default is 'undefined'
contactPoints: ["10.0.0.2"]
},
exec: { // default is '{}'
prepare: false // default is 'true'
}
});
cassanKnex.on("ready", function (err) {...});
```
or, using a custom `dse-driver` connection:
```js
// create a new dse-driver connection
var dse = require("dse-driver");
var dseClient = new dse.Client({
contactPoints: ["10.0.0.2"],
queryOptions: {
prepare: true
},
socketOptions: {
readTimeout: 0
},
profiles: []
});
// initialize dse-driver connection
dseClient.connect(function (err) {
if (err) {
console.log("Error initializing dse-driver", err);
}
else {
// provide connection to cassanknex constructor
var cassanKnex = require("cassanknex")({
connection: dseClient,
debug: false
});
cassanKnex.on("ready", function (err) {
// ...
});
}
});
```
#### <a name="Quickstart"></a>Quickstart

@@ -671,2 +738,5 @@

- 1.15.0
- Add bring-your-own-driver support.
- Allow supplying clustered columns via array input in the `createColumnFamily` `primary` annotation, per issue [#35](https://github.com/azuqua/cassanknex/issues/35).
- 1.14.0

@@ -728,3 +798,4 @@ - Add QueryModifiers `withOptions`, `limitPerPartition`, `ttl`, `add` and `remove`, `increment` and `decrement`.

[cassandra-driver-url]: https://github.com/datastax/nodejs-driver
[dse-driver-url]: https://github.com/datastax/nodejs-driver-dse
[cassandra-driver-docs-url]: http://docs.datastax.com/en/drivers/nodejs/2.1/Client.html
[knexjs-url]: http://knexjs.org/

@@ -397,6 +397,16 @@ /**

case "PRIMARY_KEY":
var keyStatements = _.map(column.options, function (option) {
return (_.isArray(option) ? "(" + _.map(option, function (op) {
return formatter.wrapQuotes(op);
}).join(", ") + ")" : formatter.wrapQuotes(option));
var keyStatements = _.map(column.options, function (option, idx) {
if (_.isArray(option) && idx === 0) {
return "(" + _.map(option, function (op) {
return formatter.wrapQuotes(op);
}).join(", ") + ")";
}
else if (_.isArray(option)) {
return _.map(option, function (op) {
return formatter.wrapQuotes(op);
}).join(", ");
}
else {
return formatter.wrapQuotes(option);
}
});

@@ -403,0 +413,0 @@ columns.push("PRIMARY KEY (" + keyStatements.join(", ") + ")");

@@ -52,2 +52,16 @@ /**

});
it("should compile a create column family statement w/ a composite partition key, where clustered columns are declared in an array.", function () {
var cql = 'CREATE COLUMNFAMILY "cassanKnexy"."columnFamily" ( "textType" TEXT, "uuidType" UUID, "intType" INT, "timestamp" TIMESTAMP, PRIMARY KEY (("textType", "uuidType"), "intType", "timestamp") ) ;'
, qb = cassanKnex("cassanKnexy")
.createColumnFamily("columnFamily")
.text("textType")
.uuid("uuidType")
.int("intType")
.timestamp("timestamp")
.primary(["textType", "uuidType"], ["intType", "timestamp"]);
var _cql = qb.cql();
assert(_cql === cql, "Expected compilation: '" + cql + "' but compiled: " + _cql);
});
it("should compile a create column family statement w/ a composite partition key and clustering.", function () {

@@ -54,0 +68,0 @@

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

, async = require("async")
, uuid = require("uuid");
, uuid = require("uuid")
, cassandraDriver = require("cassandra-driver");

@@ -30,13 +31,33 @@

this.timeout(0);
cassanKnex = require("../../index")({
connection: {
contactPoints: ["127.0.0.1"]
async.series([
function (next) {
// test connection using included cassandra-driver
var smoke = require("../../index")({
connection: {
contactPoints: ["127.0.0.1"]
},
debug: false
});
smoke.on("ready", function (err) {
assert(!err, err);
next(err);
});
},
debug: false
});
cassanKnex.on("ready", function (err) {
assert(!err, "Error connecting to cassandra", err);
done();
});
function (next) {
var cassandra = new cassandraDriver.Client({
contactPoints: ["127.0.0.1"]
});
cassandra.connect(function (err) {
assert(!err, "Error connecting to cassandra", err);
cassanKnex = require("../../index")({
connection: cassandra,
debug: false
});
cassanKnex.on("ready", function (_err) {
assert(!_err, _err);
next();
});
});
}
], done);
});

@@ -43,0 +64,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