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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cassandra-co

v0.4.1

Published

A very basic ORM and Client for Cassandra, inspired by 3logic's apollo-cassandra

Readme

cassandra-co

Join the chat at https://gitter.im/kunalgolani/cassandra-co npm version npm downloads GitHub issues Deps Dev Deps Peer Deps

A very basic ORM and Client for Cassandra, inspired by 3logic's apollo-cassandra.


Motivation

  • apollo-cassandra requires you to define the schema in code. This means that any time the DB schema is altered, the code also needs to be updated. The code needs to be aware of the schema in the DB even if it's not otherwise using all columns of a table.
  • When I looked into the internals of apollo-cassandra before starting this project, I couldn't find evidence of it using prepared statements. With Cassandra, if you're executing the same CQL query with different paramters repeatedly, preparing it makes its execution faster.

Usage

Installation

npm install --save cassandra-co

Promises and yields

All asynchronous operations return a Promise. Using co or koa, these promises can also be yielded. This documentation uses yield instead of .then() on the Promises.

Example

// Promise
asyncOperation().then(function(result) {
    // use the result here
});

// yield
var result = yield asyncOperation();
// use the result here

Instantiation

Parameters

  • {String} keyspace: The keyspace to operate on
  • {Array} hosts: Hostnames of cassandra servers
  • {Object} options [optional]: Any other client options as defined in http://www.datastax.com/drivers/nodejs/2.0/global.html#ClientOptions.

Example Initialize cassandra-co with game_of_thrones keyspace and local Cassandra

var db = require('cassandra-co')('game_of_thrones', ['127.0.0.1']);

Model

Parameters

  • {String} table: The name of the table

Example Initialize the model for characters table

var Characters = yield db.getModel('characters');

SELECT

Parameters

  • {Object} criteria [optional]: The where clause criteria, with column names as keys, and values as:
    • value for exact match, or
    • {Object} where:
      • operators as keys and operands as values for numerical comparison
      • in as key and {Array} of values for in clause
      • contains or containsKey as key and the respective value or key to check for in the set, list or map as value
  • {Object} clauses [optional]: Additional clauses such as:
    • distinct: ['column1', 'column2']
    • count: true
    • orderBy: column_name for default (ascending), or {Object} with order (asc|desc) as key and column_name as value
    • limit: 100
    • allowFiltering: true
    • raw: not wrapped in a cassandra-co object
  • {Object} options [optional]: Any other query options as defined in http://www.datastax.com/drivers/nodejs/2.0/global.html#QueryOptions

Example Find at max 5 Starks, born before Robert's Rebellion, sorted younger to older

var starks = yield Characters.find({
    house: 'Stark',
    born: {
        '<': 282
    }
}, {
    limit: 5,
    orderBy: {
        desc: 'born'
    }
});

INSERT

Parameters

  • {Object} data: Data to initialize row instance with, column names as keys
  • {Object} clauses [optional]: ttl and / or timestamp for the row being saved

Example Add a new row to characters with a ttl of 14 years

var joff = new Characters({
    name: 'Joffrey',
    house: 'Baratheon'
    born: 286
});

yield joff.save({
    ttl: 60 * 60 * 24 * 365 * 14
});

UPDATE

Parameters

  • {Object} clauses [optional]: ttl and / or timestamp for the row being saved

Example Change the name of the youngest Stark born before Robert's Rebellion to Ben

starks[0].name = 'Ben';
yield starks[0].save();

Counters

Parameters

  • {String} column [optional]: the specific counter column to increment, not required if there's only one such column
  • {Number} by [optional]: the amount to increment the counter by, assumed 1 if not given

Example Increment the kills for Daenerys Targaryen whether or not the row exists, and decrement the kills for Jaime Lannister by 2

var Kills = yield db.getModel('kills'),
    danysKills = new Kills({character: 'Daenerys Targaryen'});
yield danysKills.increment();

var kingslayersKillses = yield Kills.find({character: 'Jaime Lannister'});
yield kingslayersKillses[0].decrement(2);

DELETE

Parameters

  • {Array} columns [optional]: If provided, the values from the given columns will be deleted; otherwise, the row will be deleted

Example Delete Ben's birth year

yield starks[0].delete('born');

Caveats

  • Only prepared statements are supported. All operations will be executed as prepared statements.

  • cassandra-co needs the following ES2015/2016 features.

    You can check if the above features are available in your javascript environment here. If you don't have them, you can get them in the following ways:

    • The --harmony flag for node.js enables all stable es6 features in the v8 engine used in your version of node.js. Details: man node | grep harmony
    • The --harmony_<feature_name> flags for node.js and io.js enable the respective features behind those flags in the v8 engine used in your version of [node|io].js. Details: node|iojs --v8-options
    • Transpilers and Polyfills such as Babel or Traceur