From cbc7b5a4a7b36b16075755f985e860ed5b0161be Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Wed, 2 Mar 2022 13:20:18 +0100 Subject: [PATCH] fix(core): update --- test/test.ts | 21 ++++++++++++++++++--- ts/index.ts | 6 +++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/test/test.ts b/test/test.ts index 6df1141..91f497e 100644 --- a/test/test.ts +++ b/test/test.ts @@ -15,7 +15,7 @@ tap.test('should start the clickhouse db', async () => { }) tap.test('should write something to the clickhouse db', async () => { - const result = await testClickhouseDb.clickhouseClient.query(`CREATE DATABASE IF NOT EXISTS lossless`); + const result = await testClickhouseDb.clickhouseClient.query(`CREATE DATABASE IF NOT EXISTS lossless`).toPromise(); console.log(result); const result2 = await testClickhouseDb.clickhouseClient.query(`CREATE TABLE IF NOT EXISTS lossless.visits ( timestamp UInt64, @@ -23,8 +23,23 @@ tap.test('should write something to the clickhouse db', async () => { os String, userAgent String, version String - )`); - console.log(result); + ) ENGINE=MergeTree() ORDER BY timestamp`).toPromise(); + console.log(result2); + const ws = testClickhouseDb.clickhouseClient.insert('INSERT INTO lossless.visits FORMAT JSONEachRow').stream(); + for(let i = 0; i <= 1000; i++) { + await ws.writeRow( + JSON.stringify({ + timestamp: Date.now(), + ip: '127.0.01', + os: 'Mac OS X', + userAgent: 'some', + version: 'someversion' + }) + ); + } + + //wait stream finish + const result3 = await ws.exec(); }) tap.start(); diff --git a/ts/index.ts b/ts/index.ts index 88f5aa3..dff167d 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -17,6 +17,10 @@ export class ClickhouseDb { * starts the connection to the Clickhouse db */ public start() { - this.clickhouseClient = new plugins.clickhouse.ClickHouse(this.options); + this.clickhouseClient = new plugins.clickhouse.ClickHouse({ + ...this.options, + basicAuth: null, + format: 'json' + }); } } \ No newline at end of file