GithubHelp home page GithubHelp logo

helenus's Introduction

Helenus

NodeJS Bindings for Cassandra

Currently the driver has full CQL support and a growing support for thrift (non-cql) commands. If you would like to contribute, please contact Russ Bradberry <[email protected]>

Build Status

Build Status

Installation

npm install helenus

Running Tests

Ensure cassandra is running on localhost:9160.

make test

For coverage

make test-cov

Usage

CQL

  var helenus = require('helenus'),
      pool = new helenus.ConnectionPool({
        hosts      : ['localhost:9160'],
        keyspace   : 'helenus_test',
        user       : 'test',
        password   : 'test1233',
        timeout    : 3000
        //cqlVersion : '3.0.0' // specify this if you're using Cassandra 1.1
      });

  //if you don't listen for error, it will bubble up to `process.uncaughtException`
  //pools act just like connection objects, so you dont have to worry about api
  //differences when using either the pool or the connection
  pool.on('error', function(err){
    console.error(err.name, err.message);
  });

  //makes a connection to the pool, this will return once there is at least one
  //valid connection, other connections may still be pending
  pool.connect(function(err, keyspace){
    if(err){
      throw(err);
    } else {
      //to use cql, access the pool object once connected
      //the first argument is the CQL string, the second is an `Array` of items
      //to interpolate into the format string, the last is the callback
      //for formatting specific see `http://nodejs.org/docs/latest/api/util.html#util.format`
      //results is an array of row objects

      pool.cql("SELECT '%s' FROM '%s' WHERE key='%s'", ['col','cf_one','key123'], function(err, results){
        console.log(err, results);
      });

      //NOTE:
      //you can also use the ? as a placeholder. eg: "SELECT ? FROM '?' WHERE key='?'"
    }
  });

Thrift

If you do not want to use CQL, you can make calls using the thrift driver

  pool.connect(function(err, keyspace){
    if(err){
      throw(err);
    }

    //first retreive the column family from the server
    //helenus will cache column families it has already seen
    keyspace.get('my_cf', function(err, cf){
      if(err){
        throw(err);
      }

      //insert something into the column family
      cf.insert('foo', {'bar':'baz'}, function(err){
        if(err){
          throw(err);
        }

        //get what we just put in
        //the driver will return a Helenus.Row object just like CQL
        cf.get('foo', function(err, row){
          if(err){
            throw(err);
          }

          row.get('bar').value // => baz
        });
      });
    });

  });

Thrift Support

Currently Helenus supports the following command for the thrift side of the driver:

  • connection.createKeyspace
  • connection.dropKeyspace
  • keyspace.createColumnFamily
  • keyspace.dropColumnFamily
  • columnFamily.insert
  • columnFamily.get
  • columnFamily.getIndexed
  • columnFamily.remove

The following support is going to be added in later releases:

  • columnFamily.rowCount
  • columnFamily.columnCount
  • columnfamily.increment
  • columnFamily.truncate
  • SuperColumns
  • CounterColumns
  • Better composite support

Row

The Helenus Row object acts like an array but contains some helper methods to make your life a bit easier when dealing with dynamic columns in Cassandra

row.count

Returns the number of columns in the row

row[N]

This will return the column at index N

results.forEach(function(row){
  //gets the 5th column of each row
  console.log(row[5]);
});

row.get(name)

This will return the column with a specific name

results.forEach(function(row){
  //gets the column with the name 'foo' of each row
  console.log(row.get('foo'));
});

row.slice(start, finish)

Slices columns in the row based on their numeric index, this allows you to get columns x through y, it returns a Helenus row object of columns that match the slice.

results.forEach(function(row){
  //gets the first 5 columns of each row
  console.log(row.slice(0,5));
});

row.nameSlice(start, finish)

Slices the columns based on part of their column name. returns a helenus row of columns that match the slice

results.forEach(function(row){
  //gets all columns that start with a, b, c, or d
  console.log(row.nameSlice('a','e'));
});

Column

Columns are returned as objects with the following structure:

  {
    name: 'Foo',       //The column name
    value: 'bar',      //The column value
    timestamp: Date(), //The date object of the timestamp for the column
    ttl: 123456        //The ttl (in milliseconds) for the columns
  }

Contributors

  • Russell Bradberry - @devdazed
  • Matthias Eder - @matthiase
  • Christoph Tavan - @ctavan

License

(The MIT License)

Copyright (c) 2011 SimpleReach <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

helenus's People

Contributors

ctavan avatar devdazed avatar elubow avatar matthiase avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.