node package manager

cassandra-simple-orm

a simple CRUD orm for cassandra helenus

install

npm install cassandra-simple-orm

api使用方法

var cass= require("cassandra-simple-orm");
cass.config({
        hosts        : ['localhost:9160'],
        keyspace     : 'keyspace',
        timeout      : 3000
    })
cass().cf("<column family name>")
cass().cf("user").get("*")
cass().cf("user").get(["name", "thumb"])
cass().cf("user").update({name: "hahaha"})
cass().cf("user").insert({key: "uuidkey", name: "hahaha"}) //insert must specify KEY first, and not allowed to use WHERE
cass().cf("user").delete() //delete all
cass().cf("user").delete(["column name"])
cass().cf("club").get(["name", "thumb"])
    .where({key: "77229190-c6e9-11e2-adcb-5f2a5769f204"})
  • 等於 eql: where({age: 20}) or where({age: {eql: 20}})
  • 大於 gt: where({age: {gt: 20} })
  • 小於 lt: where({age: {lt: 20} })
  • 大於等於 gte: where({age: {gte: 20} })
  • 小於等於 lte: where({age: {lte: 20} })
cass().cf("club").get(["name", "thumb"]).exec(function(err, results){
	//..
	});
get("*")
get(["name", "thumb"])
cass().cf("user").get("*").exec(function (err, results) {
  	if(err) throw err;
  	//deal with results
  })
cass().cf("user").first("*").exec(function (err, results) {
  	if(err) throw err;
  	//deal with results
  })
cass().cf("club_member").getCols("*").exec(function (err, results) {
  	if(err) throw err;
  	//deal with results
  })

Row object 是 Helenus 的row object, 參考 Helenus document

在exec前, 加上toArray(), toObj(), 如果沒加, 就會回傳row object

 cass().clear().cf("club").get(["name", "thumb"])
  	  .where({url: {eql: "123123"}})
  	  .toObj()
  	  .exec(function (err, results) {
      	//
      })
cass().cf("user").update({name: "howhow", email: "123@123.com"})
  	  .where({key: "0aacb3b0-c51d-11e2-b9de-1b8643031865"})
  	  .exec(function (err) {
  	  	//
  	  	})
cass().cf("user").insert({key: "0aacb3b0-c51d-11e2-b9de-1b8643031865",name: "howhow123", email: "123@123.com"})
  	 .exec(function (err) {
  	  	//
  	  	})
cass().cf("user").delete(["extra"])
      		.where({key: "0aacb3b0-c51d-11e2-b9de-1b8643031865"})
      		.exec(function (err) {
	      	//
	      })
cass().cf("user").delete()
      		.where({key: "0aacb3b0-c51d-11e2-b9de-1b8643031865"})
      		.exec(function (err) {
	      	//
	      })