Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add param test, fix formatting (spaces to tabs) #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions test/04-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ describe ("select data from database", function () {
});
});

it ("select with parameters", function (done) {

var ch = new ClickHouse ({host: host, port: port});

ch.query ("SELECT number FROM system.numbers LIMIT {num:Int}", {queryOptions: {param_num: 8}, format: "CSV"}, function (err, result) {

assert (!err, err);

assert (result.match (/1\n2\n3\n4\n5\n6\n7/));

done ();

});
});

it("can cancel an ongoing select by calling destroy", function (done) {
var RecordStream = require("../src/streams").RecordStream;
if (typeof RecordStream.prototype.destroy !== "function") {
Expand Down
130 changes: 65 additions & 65 deletions test/05-insert.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,89 +296,89 @@ describe ("insert data", function () {

});

it ("creates a table 4", function (done) {
var ch = new ClickHouse ({host: host, port: port, queryOptions: {database: dbName}});
ch.query ("CREATE TABLE t4 (arrayString Array(String), arrayInt Array(UInt32)) ENGINE = Memory", function (err, result) {
assert (!err);
it("creates a table 4", function (done) {
var ch = new ClickHouse({ host: host, port: port, queryOptions: { database: dbName } });
ch.query("CREATE TABLE t4 (arrayString Array(String), arrayInt Array(UInt32)) ENGINE = Memory", function (err, result) {
assert(!err);

done ();
});
});
done();
});
});

it ("inserts array with format JSON using stream", function (done) {
var ch = new ClickHouse ({host: host, port: port});
it("inserts array with format JSON using stream", function (done) {
var ch = new ClickHouse({ host: host, port: port });

var stream = ch.query ("INSERT INTO t4", {queryOptions: {database: dbName}, format: "JSONEachRow"}, function (err, result) {
assert (!err, err);
var stream = ch.query("INSERT INTO t4", { queryOptions: { database: dbName }, format: "JSONEachRow" }, function (err, result) {
assert(!err, err);

ch.query ("SELECT * FROM t4", {syncParser: true, queryOptions: {database: dbName}, dataObjects: "JSON"}, function (err, result) {
assert.deepEqual (result.data[0].arrayString, ['first', 'second']);
assert.deepEqual (result.data[0].arrayInt, [1, 0, 100]);
ch.query("SELECT * FROM t4", { syncParser: true, queryOptions: { database: dbName }, dataObjects: "JSON" }, function (err, result) {
assert.deepEqual(result.data[0].arrayString, ['first', 'second']);
assert.deepEqual(result.data[0].arrayInt, [1, 0, 100]);

done ();
});
});
done();
});
});

stream.write ({
arrayString: ['first', 'second'],
arrayInt: [1, 0, 100]
});
stream.write({
arrayString: ['first', 'second'],
arrayInt: [1, 0, 100]
});

stream.end ();
});
stream.end();
});

it ("creates a table 5", function () {
var ch = new ClickHouse ({host: host, port: port, queryOptions: {database: dbName}});
return ch.querying ("CREATE TABLE t5 (a UInt8, b Float32, x Nullable(String), z DateTime) ENGINE = Memory");
});
it ("creates a table 5", function () {
var ch = new ClickHouse ({host: host, port: port, queryOptions: {database: dbName}});
return ch.querying ("CREATE TABLE t5 (a UInt8, b Float32, x Nullable(String), z DateTime) ENGINE = Memory");
});

it ("inserts csv with FORMAT clause", function (done) {
var ch = new ClickHouse ({host: host, port: port});
var stream = ch.query ("INSERT INTO t5 FORMAT CSV", {queryOptions: {database: dbName}}, function (err, result) {
assert (!err, err);
it ("inserts csv with FORMAT clause", function (done) {
var ch = new ClickHouse ({host: host, port: port});
var stream = ch.query ("INSERT INTO t5 FORMAT CSV", {queryOptions: {database: dbName}}, function (err, result) {
assert (!err, err);

ch.query ("SELECT * FROM t5", {syncParser: true, queryOptions: {database: dbName}}, function (err, result) {
ch.query ("SELECT * FROM t5", {syncParser: true, queryOptions: {database: dbName}}, function (err, result) {

assert.equal (result.data[0][0], 0);
assert.equal (result.data[0][1], 0);
assert.equal (result.data[0][2], null);
assert.equal (result.data[0][3], '1970-01-02 00:00:00');
assert.equal (result.data[1][0], 1);
assert.equal (result.data[1][1], 1.5);
assert.equal (result.data[1][2], '1');
assert.equal (result.data[1][3], '2050-01-01 00:00:00');
assert.equal (result.data[0][0], 0);
assert.equal (result.data[0][1], 0);
assert.equal (result.data[0][2], null);
assert.equal (result.data[0][3], '1970-01-02 00:00:00');
assert.equal (result.data[1][0], 1);
assert.equal (result.data[1][1], 1.5);
assert.equal (result.data[1][2], '1');
assert.equal (result.data[1][3], '2050-01-01 00:00:00');

done ();
done ();

});
});
stream.write('0,0,\\N,"1970-01-02 00:00:00"\n1,1.5,"1","2050-01-01 00:00:00"')
stream.end ();
});
stream.write('0,0,\\N,"1970-01-02 00:00:00"\n1,1.5,"1","2050-01-01 00:00:00"')
stream.end ();
});

it ("select data with FORMAT clause", function () {
var ch = new ClickHouse ({host: host, port: port});
return ch.querying("SELECT * FROM t5 FORMAT Values", {queryOptions: {database: dbName}})
.then((data) => {
assert.equal (data, `(0,0,NULL,'1970-01-02 00:00:00'),(1,1.5,'1','2050-01-01 00:00:00')`)
})
});
it ("select data with FORMAT clause", function () {
var ch = new ClickHouse ({host: host, port: port});
return ch.querying("SELECT * FROM t5 FORMAT Values", {queryOptions: {database: dbName}})
.then((data) => {
assert.equal (data, `(0,0,NULL,'1970-01-02 00:00:00'),(1,1.5,'1','2050-01-01 00:00:00')`)
})
});

it ("select data with GET method and FORMAT clause", function () {
var ch = new ClickHouse ({host: host, port: port, useQueryString: true});
return ch.querying("SELECT * FROM t5 FORMAT Values", {queryOptions: {database: dbName}})
.then((data) => {
assert.equal (data, `(0,0,NULL,'1970-01-02 00:00:00'),(1,1.5,'1','2050-01-01 00:00:00')`)
})
});
it ("select data with GET method and FORMAT clause", function () {
var ch = new ClickHouse ({host: host, port: port, useQueryString: true});
return ch.querying("SELECT * FROM t5 FORMAT Values", {queryOptions: {database: dbName}})
.then((data) => {
assert.equal (data, `(0,0,NULL,'1970-01-02 00:00:00'),(1,1.5,'1','2050-01-01 00:00:00')`)
})
});

it ("select data with GET method and format option", function () {
var ch = new ClickHouse ({host: host, port: port, useQueryString: true});
return ch.querying("SELECT * FROM t5", {queryOptions: {database: dbName}, format: 'Values'})
.then((data) => {
assert.equal (data, `(0,0,NULL,'1970-01-02 00:00:00'),(1,1.5,'1','2050-01-01 00:00:00')`)
})
});
it ("select data with GET method and format option", function () {
var ch = new ClickHouse ({host: host, port: port, useQueryString: true});
return ch.querying("SELECT * FROM t5", {queryOptions: {database: dbName}, format: 'Values'})
.then((data) => {
assert.equal (data, `(0,0,NULL,'1970-01-02 00:00:00'),(1,1.5,'1','2050-01-01 00:00:00')`)
})
});

after (function (done) {

Expand Down