Gathering detailed insights and metrics for yb-ycql-driver
Gathering detailed insights and metrics for yb-ycql-driver
Gathering detailed insights and metrics for yb-ycql-driver
Gathering detailed insights and metrics for yb-ycql-driver
YugabyteDB Node.js Driver for the Cassandra-compatible YCQL API
npm install yb-ycql-driver
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (99.78%)
PowerShell (0.22%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
2 Stars
939 Commits
6 Watchers
14 Branches
3 Contributors
Updated on Dec 18, 2019
Latest Version
4.0.0
Package Id
yb-ycql-driver@4.0.0
Unpacked Size
792.08 kB
Size
181.86 kB
File Count
89
NPM Version
6.5.0
Node Version
10.15.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A modern, feature-rich and highly tunable Node.js client library for Apache Cassandra (1.2+) using exclusively Cassandra's binary protocol and Cassandra Query Language v3. Use the DSE Node.js driver for better compatibility and support for DataStax Enterprise.
1$ npm install cassandra-driver
You can use the project mailing list or create a ticket on the Jira issue tracker. Additionally, you can use the #datastax-drivers
channel in the DataStax Academy Slack.
1const cassandra = require('cassandra-driver'); 2const client = new cassandra.Client({ contactPoints: ['h1', 'h2'], localDataCenter: 'datacenter1', keyspace: 'ks1' }); 3 4const query = 'SELECT name, email FROM users WHERE key = ?'; 5client.execute(query, [ 'someone' ]) 6 .then(result => console.log('User with email %s', result.rows[0].email));
Alternatively, you can use the callback-based execution for all asynchronous methods of the API.
1client.execute(query, [ 'someone' ], function(err, result) { 2 assert.ifError(err); 3 console.log('User with email %s', result.rows[0].email); 4});
Using prepared statements provides multiple benefits. Prepared statements are parsed and prepared on the Cassandra nodes and are ready for future execution. Also, when preparing, the driver retrieves information about the parameter types which allows an accurate mapping between a JavaScript type and a Cassandra type.
The driver will prepare the query once on each host and execute the statement with the bound parameters.
1// Use query markers (?) and parameters 2const query = 'UPDATE users SET birth = ? WHERE key=?'; 3const params = [ new Date(1942, 10, 1), 'jimi-hendrix' ]; 4// Set the prepare flag in the query options 5client.execute(query, params, { prepare: true }) 6 .then(result => console.log('Row updated on the cluster'));
When using #eachRow()
and #stream()
methods, the driver parses each row as soon as it is received,
yielding rows without buffering them.
1// Reducing a large result 2client.eachRow('SELECT time, val FROM temperature WHERE station_id=', ['abc'], 3 function(n, row) { 4 // The callback will be invoked per each row as soon as they are received 5 minTemperature = Math.min(row.val, minTemperature); 6 }, 7 function (err) { 8 assert.ifError(err); 9 } 10);
The #stream()
method works in the same way but instead of callback it returns a Readable Streams2 object
in objectMode
that emits instances of Row
.
It can be piped downstream and provides automatic pause/resume logic (it buffers when not read).
1client.stream('SELECT time, val FROM temperature WHERE station_id=', [ 'abc' ]) 2 .on('readable', function () { 3 // 'readable' is emitted as soon a row is received and parsed 4 let row; 5 while (row = this.read()) { 6 console.log('time %s and value %s', row.time, row.val); 7 } 8 }) 9 .on('end', function () { 10 // Stream ended, there aren't any more rows 11 }) 12 .on('error', function (err) { 13 // Something went wrong: err is a response error from Cassandra 14 });
User defined types (UDT) are represented as JavaScript objects.
For example: Consider the following UDT and table
1CREATE TYPE address ( 2 street text, 3 city text, 4 state text, 5 zip int, 6 phones set<text> 7); 8CREATE TABLE users ( 9 name text PRIMARY KEY, 10 email text, 11 address frozen<address> 12);
You can retrieve the user address details as a regular JavaScript object.
1const query = 'SELECT name, address FROM users WHERE key = ?'; 2client.execute(query, [ key ], { prepare: true }) 3 .then(result => { 4 const row = result.first(); 5 const address = row.address; 6 console.log('User lives in %s, %s - %s', address.street, address.city, address.state); 7 });
Read more information about using UDTs with the Node.js Driver.
All driver methods use a default fetchSize
of 5000 rows, retrieving only first page of results up to a
maximum of 5000 rows to shield an application against accidentally large result sets. To retrieve the following
records you can use the autoPage
flag in the query options of #eachRow()
and #stream()
methods.
1//Imagine a column family with millions of rows 2const query = 'SELECT * FROM largetable'; 3client.eachRow(query, [], { autoPage: true }, function (n, row) { 4 // This function will be invoked per each of the rows in all the table 5}, endCallback);
You can execute multiple statements in a batch to update/insert several rows atomically even in different column families.
1const queries = [ 2 { 3 query: 'UPDATE user_profiles SET email=? WHERE key=?', 4 params: [ emailAddress, 'hendrix' ] 5 }, 6 { 7 query: 'INSERT INTO user_track (key, text, date) VALUES (?, ?, ?)', 8 params: [ 'hendrix', 'Changed email', new Date() ] 9 } 10]; 11client.batch(queries, { prepare: true }) 12 .then(result => console.log('Data updated on cluster'));
There are few data types defined in the ECMAScript specification, this usually represents a problem when you are trying to deal with data types that come from other systems in JavaScript.
The driver supports all the CQL data types in Apache Cassandra (3.0 and below) even for types with no built-in JavaScript representation, like decimal, varint and bigint. Check the documentation on working with numerical values, uuids and collections.
Instances of Client()
are EventEmitter
and emit log
events:
1client.on('log', function(level, className, message, furtherInfo) { 2 console.log('log event: %s -- %s', level, message); 3});
The level
being passed to the listener can be verbose
, info
, warning
or error
.
Note: DataStax products do not support big-endian systems.
Help us focus our efforts! Provide your input on the Platform and Runtime Survey (we kept it short).
This driver is based on the original work of Jorge Bay on node-cassandra-cql and adds a series of advanced features that are common across all other DataStax drivers for Apache Cassandra.
The development effort to provide an up to date, high performance, fully featured Node.js Driver for Apache Cassandra will continue on this project, while node-cassandra-cql will be discontinued.
Copyright 2018, YugaByte, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
No vulnerabilities found.
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More