0.0.14 • Published 9 years ago

cql-tx v0.0.14

Weekly downloads
4
License
ISC
Repository
github
Last release
9 years ago

Usage

  • install cql-tx module

    	npm install cql-tx
  • Go to cql-tx folder under node_modules folder update config.js file for logging path and cassandra configurations.

var config = {
		restPort : 8080,
		websocketPort : 8081,
		trxClearanceIntervalInMins : 10,
		keyspace : 'mykeyspace',
		cassandraClient : {contactPoints: ['127.0.0.1'], keyspace: 'mykeyspace'},
		timezone : '+0300',
		winstonTransports : function(winston){
							return [
		                      new winston.transports.File({
		                          level: 'debug',
		                          filename: '/data/cqltx/logs/all-logs.log',
		                          handleExceptions: true,
		                          json: true,
		                          maxsize: 5242880, //5MB
		                          maxFiles: 5,
		                          colorize: false
		                      }),
		                      new winston.transports.Console({
		                          level: 'debug',
		                          handleExceptions: true,
		                          json: false,
		                          colorize: true
		                      })
		                  ];
		}
}
  • For transaction tables , execute init.js ;
	node init.js
  • Start cql-tx (rest server will start listening 8080 port , defined on config js) ;
	npm start cql-tx
  • For testing create the following user table ;
	create table users(fname text,lname text,user_id bigint,primary key (user_id));
  • open a transaction by the following curl command ;
curl -H "Content-Type: application/json" -X POST -d '{"commandType" : "openTransaction" }' http://localhost:8080/cqltx
  • exeute the cql (change the transaction id with the value that's returned by open-transaction);
curl -H "Content-Type: application/json" -X POST -d '{"commandType" : "execute", "txId" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" ,"cql":"insert into users(user_id) values(64222)" }' http://localhost:8080/cqltx
  • check the user table , if the "64222" entry exists or not.

  • commit the transaction ;

curl -H "Content-Type: application/json" -X POST -d '{"commandType" : "commitTransaction", "txId" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" }' http://localhost:8080/cqltx
  • or rollback;
curl -H "Content-Type: application/json" -X POST -d '{"commandType" : "rollbackTransaction", "txId" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" }' http://localhost:8080/cqltx

You can use java restful interface driver cqltx-rest-driver instead of curl.(download cqltx-rest-driver)

...
	// cql-tx rest server address
	CqlSessionFactory factory = new CqlSessionFactory(new URL("http://localhost:8080/cqltx"));
	//create new session	
 	CqlSession session = factory.createNewSession();
	session.execute("insert into grouped_users(user_id,fname,lname, group,age) values(7004,'test1','test2','engineering',21)");
	//commit the session	
	session.commit();

Tools

Created with Nodeclipse (Eclipse Marketplace, site)

Nodeclipse is free open-source project that grows with your contributions.

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago

0.0.0

9 years ago