npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cql-client

v0.3.3

Published

cassandra CQL driver uses Native Protocol v2

Downloads

41

Readme

cql-client

Build Status Coverage Status Coverage Status npm license

Node.js driver for cassandra on Cassandra Binary Protocol v2.

Features

  • CQL binary protocol v2
  • Automatic discovery of cluster peers
  • Fail-over cluster peers
  • Retry queries when disconnected from servers
  • Paging large result set with paging state
  • Events

Quick start

var client = require('cql-client').createClient({
  hosts: ['127.0.0.1']
});

client.execute('SELECT * FROM system.peers', function(err, rs) {
  var rows = rs.rows;
  rows.forEach(function(row) {
    console.log(row.peer);
    console.log(row.host_id);
    ..
  });
});

Usage

Install library

npm install cql-client --save

Create a client

var cql = require('cql-client');
var client = cql.createClient({ hosts: ['127.0.0.1'], keyspace: 'ks' });

Execute queries

client.execute('SELECT * FROM table', function(err, rs) {
  rs.rows.forEach(function(row) {
    console.log(row);
  });
});

Execute prepared queries

client.execute(
  'INSERT INTO table (id, v1, v2) VALUES (?, ?, ?)',
  [1000, 'foo', 'bar'],
  function(err) {
    ...
  }
);

Batch

var batch = client.batch();
batch.add('UPDATE table SET v1 = ? WHERE id = ?', ['101', 1001]);
batch.add('UPDATE table SET v1 = ? WHERE id = ?', ['101', 1001]);
batch.add('DELETE FROM table WHERE id = ?', ['102']);
batch.commit(function(err) {
  ..
});

Read data with cursor

var cursor = client.execute('SELECT * FROM table', function(err, rs) {
  var cursor = rs.cursor();
  cursor.on('row', function(row) {
    console.log(row);
  });
  cursor.on('error', function(err) {
    ..
  });
  cursor.on('end', function() {
    console.log('done');
  });
});

API

CQL

cql.createClient([options])

Create a client with options. The created client will connect the cluster automatically.

  • options
  • hosts List of cassandra hosts you are connecting to. Use array to connect multiple hosts.
  • keyspace Name of the default keyspace.
  • autoDetect Set true to detect peers automatically. (Optional)
  • connsPerHost The size of connection pool per host. (Default: 2)
  • connectTimeout Milliseconds to determine connections are timed out. (Default: 5000)
  • reconnectInterval Milliseconds of interval for reconnecting. (Default: 5000)
  • preparedCacheSize Size of cache for prepared statement. (Default: 10000)

Client

client.connect(cb)

Connect to the cluster. Note that you do not need to call the method since client will connect automatically.

  • cb callback when connected

client.close()

Close the connection to the cluster.

client.getAvailableConnection()

Get available connection from connections.

client.execute(query, [values], [options], callback)

Execute CQL. It will use prepared query when values are specified.

  • query Query statement to be executed.
  • values Array of bound values.
  • options
  • consistencyLevel Consistency level of the query. cql.CL.ONE,THREE,QUORUM,ALL,LOCAL_QUORUM,EACH_QUORUM
  • pageSize Paging size of the result.
  • pagingState Paging state of the query.
  • serialConsistency Serial consistency of the query.
  • callback Callback with error and result set.

client.batch()

Create batch instance. See Batch.

ResultSet

Result data of the query.

resultSet.metadata

Metadata of result rows and columns.

resultSet.rows

Array of rows.

resultSet.cursor()

Create cursor instance of the result.

Cursor

cursor.on(event, listener)

Register event listener.

  • Events
  • row when cursor have an available row
  • end when cursor ends
  • error when error occurs

cursor.abort()

Abort cursor. It will fire end event.

Batch

batch.add(query, [values])

Add query to the batch.

  • query Query statement.
  • values Array of values to be bound.

batch.option(options)

Set option parameters to the batch.

  • options Same as options of client.execute()

batch.commit(callback)

Commit queries. It will clean up queries in the batch after committing.

TODO

  • Authentication

License

See LICENSE

Copyright (C) Suguru Namura

patched cql-protocol. See LICENSE and cql-protocol