Skip to content
This repository was archived by the owner on Feb 22, 2019. It is now read-only.

deserialize the key #111

Merged
merged 3 commits into from
Oct 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,25 +449,36 @@ Connection.prototype.cql = function(cmd, args, options, callback){
}
}

if (this.cqlVersion === '3.0.0' || (this.version[0] === '19' && this.version[1] > '33')) {
if(options.gzip === true){
zlib.deflate(cql, function(err, cqlz){
self.execute('execute_cql3_query', cqlz, ttype.Compression.GZIP, self.consistencylevel, onReturn);
});
} else {
self.execute('execute_cql3_query', cql, ttype.Compression.NONE, self.consistencylevel, onReturn);
}
}
// fallback to older version
else {
if(options.gzip === true){
function execQuery (v) {
if(v===3)
if(options.gzip === true){
zlib.deflate(cql, function(err, cqlz){
self.execute('execute_cql3_query', cqlz, ttype.Compression.GZIP, self.consistencylevel, onReturn);
});
} else {
self.execute('execute_cql3_query', cql, ttype.Compression.NONE, self.consistencylevel, onReturn);
}
else
if(options.gzip === true){
zlib.deflate(cql, function(err, cqlz){
self.execute('execute_cql_query', cqlz, ttype.Compression.GZIP, onReturn);
});
} else {
self.execute('execute_cql_query', cql, ttype.Compression.NONE, onReturn);
}
}


if(this.cqlVersion) //if cqlVersion defined
if(this.cqlVersion === '3.0.0' && (this.version[0] === '19' && this.version[1] > '33')) //if version support cql3
execQuery(3);
else //fallback to cql2, or choose to use cql2
execQuery(2);
else if(this.version[0] === '19' && this.version[1] > '33') //if not defined, then exec query based on version
execQuery(3);
else
execQuery(2);

};

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ var Row = function(data, schema){
}

this._map[name] = this.length - 1;
}else{
this.key= deserializeValue(item.value);
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/cql2.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ module.exports = {
});
},

'test cql create uuid column family':function(test, assert){
conn.cql(config['create_uuid_cf#cql'], function (err, res){
assert.ifError(err);
assert.ok(res === undefined);
test.finish();
});
},

'test cql update':function(test, assert){
conn.cql(config['update#cql'], function(err, res){
assert.ifError(err);
Expand Down Expand Up @@ -226,6 +234,21 @@ module.exports = {
});
},

'test cql uuid key decode':function(test, assert){
conn.cql(config['update_uuid#cql'], ["body", "07ad2230-ee44-11e2-91e2-0800200c9a66"],function(err, res){
assert.ifError(err);
assert.ok(res === undefined);

conn.cql(config['select_uuid#cql'], ["07ad2230-ee44-11e2-91e2-0800200c9a66"], function(err, res){
assert.ifError(err);
assert.ok(res.length === 1);
assert.ok(res[0] instanceof Helenus.Row);
assert.ok(res[0].key.toString() === "07ad2230-ee44-11e2-91e2-0800200c9a66");
test.finish();
});
});
},

'test cql drop column family':function(test, assert){
conn.cql(config['drop_cf#cql'], function(err, res){
assert.ifError(err);
Expand Down
3 changes: 3 additions & 0 deletions test/helpers/cql2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"create_cf#cql" : "CREATE COLUMNFAMILY cql_test (KEY text PRIMARY KEY) WITH default_validation=UTF8Type and comparator=UTF8Type",
"create_reversed_cf#cql" : "CREATE COLUMNFAMILY cql_rev_test (KEY text PRIMARY KEY) WITH default_validation=UTF8Type and comparator='UTF8Type(reversed=true)'",
"create_counter_cf#cql" : "CREATE COLUMNFAMILY cql_cnt_test (KEY text PRIMARY KEY) WITH default_validation=CounterColumnType and comparator=UTF8Type",
"create_uuid_cf#cql" : "CREATE COLUMNFAMILY cql_uuid_test (KEY uuid PRIMARY KEY) WITH default_validation=UTF8Type and comparator=UTF8Type",
"drop_ks#cql" : "DROP KEYSPACE helenus_cql_test",
"drop_cf#cql" : "DROP COLUMNFAMILY cql_test",
"update#cql" : "UPDATE cql_test SET foo='bar' WHERE KEY='foobar'",
Expand All @@ -13,6 +14,8 @@
"select*#cql" : "SELECT * FROM cql_test WHERE KEY='foobar'",
"select_counter#cql" : "SELECT foo FROM cql_cnt_test WHERE KEY='foobar'",
"select_reversed#cql" : "SELECT foo FROM cql_rev_test WHERE KEY='foobar'",
"update_uuid#cql" : "UPDATE cql_uuid_test SET body=? WHERE KEY=?",
"select_uuid#cql" : "SELECT * FROM cql_uuid_test WHERE KEY=?",
"count#cql" : "SELECT COUNT(*) FROM cql_test WHERE KEY='foobar'",
"delete#cql" : "DELETE FROM cql_test WHERE KEY='foobar'",
"select2#cql" : "SELECT * FROM cql_test WHERE KEY='%s'",
Expand Down