![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
node-cassandra-cql
Advanced tools
node-cassandra-cql is a Node.js CQL driver for Apache Cassandra's native protocol with a small dependency tree written in pure javascript.
$ npm install node-cassandra-cql
row.get('first_name')
// Creating a new connection pool to multiple hosts.
var Client = require('node-cassandra-cql').Client;
var hosts = ['host1:9042', 'host2:9042', 'host3', 'host4'];
var client = new Client({hosts: hosts, keyspace: 'Keyspace1'});
Client() accepts an object with these slots, only hosts
is required:
hosts: String list in host:port format. Port is optional (defaults to 9042).
keyspace: Name of keyspace to use.
username: User for authentication.
password: Password for authentication.
version: Currently only '3.0.0' is supported.
staleTime: Time in milliseconds before trying to reconnect.
maxExecuteRetries: Maximum amount of times an execute can be retried
using another connection, in case the server is unhealthy.
getAConnectionTimeout: Maximum time in milliseconds to wait for a connection from the pool.
Queries are performed using the execute()
method. For example:
// Reading
client.execute('SELECT key, email, last_name FROM user_profiles WHERE key=?', ['jbay'],
function(err, result) {
if (err) console.log('execute failed');
else console.log('got user profile with email ' + result.rows[0].get('email'));
}
);
// Writing
client.execute('UPDATE user_profiles SET birth=? WHERE key=?', [new Date(1950, 5, 1), 'jbay'],
types.consistencies.quorum,
function(err) {
if (err) console.log("failure");
else console.log("success");
}
);
execute()
and executeAsPrepared()
accept the following arguments
cqlQuery : The cql query to execute, with ? as parameters
arguments: Array of arguments that will replace the ? placeholders. Optional.
consistency : The level of consistency. Optional, defaults to quorum.
callback : The callback function with 2 arguments: err and result
// Shutting down a pool
cqlClient.shutdown(function() { console.log("connection pool shutdown"); });
execute(query, args, consistency, callback)
executeAsPrepared(query, args, consistency, callback)
shutdown(callback)
execute()
and executeAsPrepared()
accepts the following arguments
query: The cql query to execute, with ? as parameters
arguments: Array of arguments that will replace the ? placeholders. Optional.
consistency: The level of consistency. Optional, defaults to quorum.
callback: The callback function with 2 arguments: err and result
open(callback)
close(callback)
execute(query, args, consistency, callback)
prepare(query, callback)
executePrepared(queryId, args, consistency, callback)
The Client
maintains a pool of opened connections to the hosts to avoid several time-consuming steps that are involed with the set up of a CQL binary protocol connection (socket connection, startup message, authentication, ...).
If you want to get lower level fine-grained control you could use the Connection
class.
var Connection = require('node-cassandra-cql').Connection;
var con = new Connection({host:'host1', port:9042, username:'cassandra', password:'cassandra'});
con.open(function(err) {
if(err) {
console.error(err);
}
else {
var query = 'SELECT key, email, last_name FROM user_profiles WHERE key=?';
con.execute(query, ['jbay'], function(err, result){
if (err) console.log('execute failed');
else console.log('got user profile with email ' + result.rows[0].get('email'));
con.close();
});
}
});
Instances of Client()
and Connection()
are EventEmitter
's and emit log
events:
var Connection = require('node-cassandra-cql').Connection;
var con = new Connection({host:'host1', port:9042, keyspace:'Keyspace1'});
con.on('log', function(level, message) {
console.log('log event: %s -- %j', level, message);
});
The level
being passed to the listener can be info
or error
.
Cassandra's bigint data types are parsed as int64.
List / Set datatypes are encoded from / decoded to Javascript Arrays.
Map datatype are encoded from / decoded to Javascript objects with keys as props.
Decimal and Varint are not parsed yet, they are yielded as byte Buffers.
node-cassandra-cql is distributed under the MIT license.
Feel free to join in if you feel like helping this project progress!
FrameReader and FrameWriter are based on node-cql3's FrameBuilder and FrameParser.
FAQs
Node.js driver for Apache Cassandra
The npm package node-cassandra-cql receives a total of 45 weekly downloads. As such, node-cassandra-cql popularity was classified as not popular.
We found that node-cassandra-cql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.