smartclickhouse/test/test.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-03-01 14:03:55 +00:00
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
import * as smartclickhouse from '../ts/index';
let testClickhouseDb: smartclickhouse.ClickhouseDb;
tap.test('first test', async () => {
testClickhouseDb = new smartclickhouse.ClickhouseDb({
url: 'http://localhost',
port: 8123,
});
});
tap.test('should start the clickhouse db', async () => {
await testClickhouseDb.start();
})
tap.test('should write something to the clickhouse db', async () => {
2022-03-02 12:20:18 +00:00
const result = await testClickhouseDb.clickhouseClient.query(`CREATE DATABASE IF NOT EXISTS lossless`).toPromise();
2022-03-01 14:03:55 +00:00
console.log(result);
const result2 = await testClickhouseDb.clickhouseClient.query(`CREATE TABLE IF NOT EXISTS lossless.visits (
timestamp UInt64,
ip String,
os String,
userAgent String,
version String
2022-03-02 12:20:18 +00:00
) 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();
2022-03-01 14:03:55 +00:00
})
tap.start();