Node.js Driver for the scylla databse engine [WIP]
Disclaimer I am not associated in any way with ScyllaDB or Datastax.
$ npm install scylladb
import {createClient} from 'scylladb';
const client = createClient({
hosts: ['0.0.0.0', '0.0.0.1'],
keyspace: 'ks1'
});
Query methods return a Promise.
// Simple statements
client.query('SELECT * FROM users')
.then(result => console.log(`User with email ${result.rows[0].email}`));
// Automatically detects prepared steatements
client.query('SELECT name, email FROM users WHERE key = ?', [ 'someone' ])
.then(result => console.log(`User with email ${result.rows[0].email}`));
It can be piped downstream and provides automatic pause/resume logic (it buffers when not read).
const stream = client.stream('SELECT time, val FROM temperature WHERE station_id=', [ 'abc' ]);
stream.on('readable', function () {
// readable is emitted as soon a row is received and parsed
let row;
while (row = this.read()) {
stream.pause();
console.log(`time ${row.time} and value ${row.value}`);
stream.resume();
}
})
.on('end', function () {
// emitted when all rows have been retrieved and read
})
.on('error', function (err) {
console.log(`Error: ${err}`)
});
ScyllaDB driver uses the NODE_DEBUG
environment variable.
NODE_DEBUG=scylladb:<priority>
The priority
being passed to debug can be info
, warn
or error
. If no level is specified, the default setting is warn
.
Once you have a database setup with a keyspace named “test” and a table “users”.
Help can be found in the wiki.
npm run test
In order to keep the driver performant and reduce complexity a few choices were made to strip or replace some of the features present in the Datastax Cassandra driver.
I am always looking for help. Reach out to get involved!
Apache 2.0 (c) 2017-2024 Frederic Charette