How to print the final request in Cassandra nodejs-driver?

I am looking for a way to print the end of a request in Cassandra nodejs-driver, i.e. CQL String after binding all the parameters so that I can debug and see which values ​​actually go to the Cassandra engine. How to do it?

var query = ' select * from shahid.tbl_raw_data where yymmddhh = ? limit ? ';
var params = [last_yymmddhh_value, settings.records_per_batch];

client.execute(query, params, {prepare: true}, function(err, result)
{           
      console.log( result );
});

I want to get a line like this

select * from shahid.tbl_raw_data where yymmddhh = '15010101' limit 100

Note. This is a simple example: I'm really working on a very complex query in a loop, so I don't want to do console.log(last_yymmddhh_value)to see the binding values.

+4
source share
2 answers

The query actually executed by the driver differs from the query text in full text, since the evaluation is performed on the server side.

, , , , (. EXECUTE), , , , .

java- Query Logger, . , . , , :

DEBUG [cluster1] [/127.0.0.1:9042] Query completed normally, took 9 ms: select * from shahid.tbl_raw_data where yymmddhh = ? limit ? [15010101, 100];

nodejs-, alex-rokabilis , , ? ( , , , , ). NODEJS-220, .

+4

function dispQuery(query, params) {
   var params_temp = Array.from(params);
   return query.replace(/\?/g, function() {
      return params_temp.shift()
   })
}

, :

client.execute(query, params, {prepare: true}, function(err, result)
{           
  console.log("Query ::%s",dispQuery(query,params));
  console.log("Result ::",result);
});
+3

Source: https://habr.com/ru/post/1625642/


All Articles