From d1cc5de87b0513ceacf6921169e41082da0d58e5 Mon Sep 17 00:00:00 2001 From: max Date: Wed, 26 Aug 2020 11:27:21 +0800 Subject: [PATCH 1/2] fix issue #56 --- src/clickhouse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clickhouse.js b/src/clickhouse.js index 14b1655..b5fc28e 100644 --- a/src/clickhouse.js +++ b/src/clickhouse.js @@ -284,7 +284,7 @@ ClickHouse.prototype.query = function (chQuery, options, cb) { var formatEnding = ''; // format should be added for data queries - if (chQuery.match (/^(?:SELECT|SHOW|DESC|DESCRIBE|EXISTS\s+TABLE)/i)) { + if (chQuery.match (/^(?:SELECT|WITH|SHOW|DESC|DESCRIBE|EXISTS\s+TABLE)/i)) { if (!options.format) options.format = options.dataObjects ? 'JSON' : 'JSONCompact'; } else if (chQuery.match (/^INSERT/i)) { From 2384959583dada764bdcfb37b0b893a2c1f47c56 Mon Sep 17 00:00:00 2001 From: lixiangyu1 Date: Fri, 4 Sep 2020 17:22:17 +0800 Subject: [PATCH 2/2] add testcase for issue#56 --- test/04-select.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/04-select.js b/test/04-select.js index b20bdda..e3b9b63 100644 --- a/test/04-select.js +++ b/test/04-select.js @@ -220,4 +220,15 @@ describe ("select data from database", function () { stream.destroy (); }); }); + + it("select query with WITH clause will produces result formatted ", function (done) { + var ch = new ClickHouse({ host: host, port: port, format: "JSON" }); + ch.query("WITH 10 as pagesize SELECT 1", { syncParser: true }, function (err, result) { + assert(!err); + assert(result.meta, "result should be Object with `data` key to represent rows"); + assert(result.data, "result should be Object with `meta` key to represent column info"); + assert(Object.prototype.toString.call(result.data[0]) === '[object Object]', "data should be formatted JSON" ) + done(); + }); + }) });