node.js + cassandra

// install cassandra from http://www.datastax.com/documentation/cassandra/2.1/cassandra/install/install_cassandraTOC.html

cqlsh

CREATE KEYSPACE testkeystore WITH replication = {'class':'SimpleStrategy', 'replication_factor':3};

CREATE TYPE testkeystore.address (
number int,
street text,
code int,
city text
);

CREATE TABLE testkeystore.person(
person_id text PRIMARY KEY,
firstname text,
lastname text,
age int,
address set< frozen

>,
phones map,
);

exit

sudo npm install -g cassandra-driver

subl cassadnra.js

var cassandra = require('cassandra-driver');

var client = new cassandra.Client({contactPoints: ['host1', '127.0.0.1'], keyspace: 'testkeystore'});

var cassandra = require('cassandra-driver');

var client = new cassandra.Client({contactPoints: ['host1', '127.0.0.1'], keyspace: 'testkeystore'});

var query = 'INSERT INTO testkeystore.person(person_id,firstname,lastname,age,address,phones) VALUES(?, ?, ?, ?, {{number:123,street:\'samplestreet\',code:4569,city:\'samplecity\'}},{\'home\':\'9764\'});'
var params = ['1', 'bob', 'bob', 35];

client.execute(query, params, {prepare: true}, function(err) {

if(err)
console.log('ERROR '+err);
else
console.log('Row inserted on the cluster');
});

nodejs cassadnra.js

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s