ode-cassadra-cql是一个ApacheCassadraCQL3二进制协议的Node.jsCQL驱动。CQL是Cassadra的查询语言。该项目提供到多个主机的连接池、查询参数,以及可通过列名获取数值和支持bigit。
示例代码:
//Creatigaewcoectiopooltomultiplehosts.varcql=require('ode-cassadra-cql');varcliet=ewcql.Cliet({hosts:['host1:9042','host2:9042'],keyspace:'keyspace1'});//Readigcliet.execute('SELECTkey,email,last_ameFROMuser_profilesWHEREkey=?',['jbay'],fuctio(err,result){if(err)cosole.log('executefailed');elsecosole.log('gotuserprofilewithemail'+result.rows[0].get('email'));});//Writigcliet.execute('UPDATEuser_profilesSETbirth=?WHEREkey=?',[ewDate(1950,5,1),'jbay'],cql.types.cosistecies.quorum,fuctio(err){if(err)cosole.log("failure");elsecosole.log("success");});//Streamigqueryrowscliet.streamRows('SELECTevet_time,temperatureFROMtemperatureWHEREstatio_id=',['abc'],fuctio(err,row){//thecallbackwillbeivokedpereachrowassooastheyarereceivedif(err)cosole.log("Ohdear...");else{cosole.log('temperaturevalue',row.get('temperature'));}});//Streamigfieldcliet.streamField('SELECTkey,photoFROMuser_profilesWHEREkey=',['jbay'],fuctio(err,row,photoStream){//thecallbackwillbeivokedpereachrowassooastheyarereceived.if(err)cosole.log("Shame...");else{//ThestreamisaReadableStream2objectstdout.pipe(photoStream);}});
评论