Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including promised-cassandra with all npm packages installed. Try it out:

var promisedCassandra = require("promised-cassandra")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

promised-cassandra v0.2.0

Q promise wrapper for Datastax Cassandra driver

Promised Cassandra

Q promise wrapper for Datastax Cassandra driver

Depends on node v6

Install

npm install --save cassandra-driver promised-cassandra

Featured Cassandra driver functions

Everything. It's proxying the Cassandra driver.

But everything is not tested though.

Tested Cassandra driver functions

  • execute
  • eachRow

Basic usage

// Initiate cassandra connection
const cassandra = require('promised-cassandra');
// If no connection options are passed, connection will default to localhost
// or use CASSANDRA_CONTACT_POINTS environment variable.
const database = cassandra({
    contactPoints: ['127.0.0.1']
});
// or if your options comes from a promise
const database = cassandra(some_promise_that_resolves_an_options_object);

// Execute some CQL
database.execute(
    'SELECT email FROM users WHERE id=?',
    [123]
)
.then(result => {
    // result.rows
    // result.first().email
});

// Run eachRow
database.eachRow('SELECT email FROM users', null, (row => {
    // row.email
})
.then(result => {
    // result.rows
});

Some extra functions

// Create a keyspace if it doesn't already exist and start using it
database.create_keyspace(
    'keyspace-name', // Keyspace name
    {class: 'SimpleStrategy', replication_factor: 1}, // Replication options
    false // Durable writes
)
.then(() => {
    // Keyspace created
});

// Create table if it doesn't already exist
database.create_table(
    'table-name',
    {
        id: 'uuid PRIMARY KEY',
        column: 'text'
    }
)
.then(() => {
    // Table created
);
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free