Apache Cassandra CQL3 二進制協議的 Node.js CQL 驅動:node-cassandra-cql
node-cassandra-cql 是一個 Apache Cassandra CQL3 二進制協議的 Node.js CQL 驅動。CQL 是 Cassandra 的查詢語言。該項目提供到多個主機的連接池、查詢參數,以及可通過列名獲取數值和支持 bigint。
示例代碼:
// Creating a new connection pool to multiple hosts.
var cql = require('node-cassandra-cql');
var client = new cql.Client({hosts: ['host1:9042', 'host2:9042'], keyspace: 'keyspace1'});
// Reading
client.execute('SELECT key, email, last_name FROM user_profiles WHERE key=?', ['jbay'],
function(err, result) {
if (err) console.log('execute failed');
else console.log('got user profile with email ' + result.rows[0].get('email'));
}
);
// Writing
client.execute('UPDATE user_profiles SET birth=? WHERE key=?', [new Date(1950, 5, 1), 'jbay'],
cql.types.consistencies.quorum,
function(err) {
if (err) console.log("failure");
else console.log("success");
}
);
// Streaming query rows
client.streamRows('SELECT event_time, temperature FROM temperature WHERE station_id=', ['abc'],
function(err, row) {
//the callback will be invoked per each row as soon as they are received
if (err) console.log("Oh dear...");
else {
console.log('temperature value', row.get('temperature'));
}
}
);
// Streaming field
client.streamField('SELECT key, photo FROM user_profiles WHERE key=', ['jbay'],
function(err, row, photoStream) {
//the callback will be invoked per each row as soon as they are received.
if (err) console.log("Shame...");
else {
//The stream is a Readable Stream2 object
stdout.pipe(photoStream);
}
}
);
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!