Skip to content

Commit

Permalink
Merge pull request #66 from evle/master
Browse files Browse the repository at this point in the history
fix issue #56
  • Loading branch information
nezed authored Sep 13, 2020
2 parents d660165 + 2384959 commit d953208
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/clickhouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
11 changes: 11 additions & 0 deletions test/04-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
})
});

0 comments on commit d953208

Please sign in to comment.