node-cassandra-cql是一个ApacheCassandraCQL3二进制协议的Node.jsCQL驱动。CQL是Cassandra的查询语言。该项目提供到多个主机的连接池、查询参数,以及可通过列名获取数值和支持bigint。
示例代码:
//Creatinganewconnectionpooltomultiplehosts.varcql=require('node-cassandra-cql');varclient=newcql.Client({hosts:['host1:9042','host2:9042'],keyspace:'keyspace1'});//Readingclient.execute('SELECTkey,email,last_nameFROMuser_profilesWHEREkey=?',['jbay'],function(err,result){if(err)console.log('executefailed');elseconsole.log('gotuserprofilewithemail'+result.rows[0].get('email'));});//Writingclient.execute('UPDATEuser_profilesSETbirth=?WHEREkey=?',[newDate(1950,5,1),'jbay'],cql.types.consistencies.quorum,function(err){if(err)console.log("failure");elseconsole.log("success");});//Streamingqueryrowsclient.streamRows('SELECTevent_time,temperatureFROMtemperatureWHEREstation_id=',['abc'],function(err,row){//thecallbackwillbeinvokedpereachrowassoonastheyarereceivedif(err)console.log("Ohdear...");else{console.log('temperaturevalue',row.get('temperature'));}});//Streamingfieldclient.streamField('SELECTkey,photoFROMuser_profilesWHEREkey=',['jbay'],function(err,row,photoStream){//thecallbackwillbeinvokedpereachrowassoonastheyarereceived.if(err)console.log("Shame...");else{//ThestreamisaReadableStream2objectstdout.pipe(photoStream);}});
评论