Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
d03f086c92 | |||
83c1e2bb4e | |||
faa5d6d542 | |||
6e06e8108b | |||
45ce23ec11 | |||
93ef6a3d6b | |||
609873b4ad | |||
4a8bbc3d13 | |||
51c2d4f6e0 | |||
45091d6b8c | |||
eae7300439 | |||
7753e58036 |
2532
package-lock.json
generated
2532
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartclickhouse",
|
"name": "@pushrocks/smartclickhouse",
|
||||||
"version": "2.0.7",
|
"version": "2.0.13",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "an odm for talking to clickhouse",
|
"description": "an odm for talking to clickhouse",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -10,16 +10,16 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild --web)",
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
"createGrafana": "docker run --name grafana -d -p 4000:3000 grafana/grafana-oss",
|
"createGrafana": "docker run --name grafana -d -p 4000:3000 grafana/grafana-oss",
|
||||||
"createClickhouse": "docker run --name some-clickhouse-server --ulimit nofile=262144:262144 -p 8123:8123 -p 9000:9000 --volume=$PWD/.nogit/testdatabase:/var/lib/clickhouse yandex/clickhouse-server"
|
"createClickhouse": "docker run --name some-clickhouse-server --ulimit nofile=262144:262144 -p 8123:8123 -p 9000:9000 --volume=$PWD/.nogit/testdatabase:/var/lib/clickhouse yandex/clickhouse-server"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.63",
|
"@gitzone/tsbuild": "^2.1.65",
|
||||||
"@gitzone/tsbundle": "^2.0.6",
|
"@gitzone/tsbundle": "^2.0.7",
|
||||||
"@gitzone/tstest": "^1.0.72",
|
"@gitzone/tstest": "^1.0.73",
|
||||||
"@pushrocks/tapbundle": "^5.0.4",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"@types/node": "^18.6.2",
|
"@types/node": "^18.6.4",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
@ -28,7 +28,7 @@
|
|||||||
"@pushrocks/smartobject": "^1.0.10",
|
"@pushrocks/smartobject": "^1.0.10",
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smarturl": "^3.0.2",
|
"@pushrocks/smarturl": "^3.0.2",
|
||||||
"@pushrocks/webrequest": "^3.0.9"
|
"@pushrocks/webrequest": "^3.0.12"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
@ -7,6 +7,7 @@ tap.test('first test', async () => {
|
|||||||
testClickhouseDb = new smartclickhouse.SmartClickHouseDb({
|
testClickhouseDb = new smartclickhouse.SmartClickHouseDb({
|
||||||
url: 'http://localhost:8123',
|
url: 'http://localhost:8123',
|
||||||
database: 'test2',
|
database: 'test2',
|
||||||
|
unref: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartclickhouse',
|
name: '@pushrocks/smartclickhouse',
|
||||||
version: '2.0.7',
|
version: '2.0.13',
|
||||||
description: 'an odm for talking to clickhouse'
|
description: 'an odm for talking to clickhouse'
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as plugins from './smartclickhouse.plugins.js';
|
import * as plugins from './smartclickhouse.plugins.js';
|
||||||
|
|
||||||
export interface IClickhouseHttpClientOptions {
|
export interface IClickhouseHttpClientOptions {
|
||||||
user?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
@ -32,19 +32,13 @@ export class ClickhouseHttpClient {
|
|||||||
|
|
||||||
public async start() {
|
public async start() {
|
||||||
this.computedProperties.parsedUrl = plugins.smarturl.Smarturl.createFromUrl(this.options.url);
|
this.computedProperties.parsedUrl = plugins.smarturl.Smarturl.createFromUrl(this.options.url);
|
||||||
this.computedProperties.parsedUrl.username = this.options.user ? this.options.user : '';
|
console.log(this.computedProperties.parsedUrl);
|
||||||
this.computedProperties.parsedUrl.password = this.options.password ? this.options.password : '';
|
|
||||||
this.computedProperties.connectionUrl = this.computedProperties.parsedUrl.toString();
|
this.computedProperties.connectionUrl = this.computedProperties.parsedUrl.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ping() {
|
public async ping() {
|
||||||
const parsedUrlForPing = plugins.smarturl.Smarturl.createFromUrl(
|
|
||||||
this.computedProperties.connectionUrl.toString()
|
|
||||||
);
|
|
||||||
parsedUrlForPing.username = null;
|
|
||||||
parsedUrlForPing.password = null;
|
|
||||||
|
|
||||||
const ping = await this.webrequestInstance.request(parsedUrlForPing.toString(), {
|
const ping = await this.webrequestInstance.request(this.computedProperties.connectionUrl.toString(), {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
timeoutMs: 1000,
|
timeoutMs: 1000,
|
||||||
});
|
});
|
||||||
@ -54,9 +48,11 @@ export class ClickhouseHttpClient {
|
|||||||
public async queryPromise(queryArg: string) {
|
public async queryPromise(queryArg: string) {
|
||||||
const returnArray = [];
|
const returnArray = [];
|
||||||
const response = await this.webrequestInstance.request(`${this.computedProperties.connectionUrl}?query=${encodeURIComponent(queryArg)}`, {
|
const response = await this.webrequestInstance.request(`${this.computedProperties.connectionUrl}?query=${encodeURIComponent(queryArg)}`, {
|
||||||
method: 'POST'
|
method: 'POST',
|
||||||
|
headers: this.getHeaders(),
|
||||||
});
|
});
|
||||||
// console.log('===================');
|
// console.log('===================');
|
||||||
|
// console.log(this.computedProperties.connectionUrl);
|
||||||
// console.log(queryArg);
|
// console.log(queryArg);
|
||||||
// console.log((await response.clone().text()).split(/\r?\n/))
|
// console.log((await response.clone().text()).split(/\r?\n/))
|
||||||
if (response.headers.get('X-ClickHouse-Format') === 'JSONEachRow') {
|
if (response.headers.get('X-ClickHouse-Format') === 'JSONEachRow') {
|
||||||
@ -78,8 +74,20 @@ export class ClickhouseHttpClient {
|
|||||||
const queryArg = `INSERT INTO ${databaseArg}.${tableArg} FORMAT JSONEachRow`;
|
const queryArg = `INSERT INTO ${databaseArg}.${tableArg} FORMAT JSONEachRow`;
|
||||||
const response = await this.webrequestInstance.request(`${this.computedProperties.connectionUrl}?query=${encodeURIComponent(queryArg)}`, {
|
const response = await this.webrequestInstance.request(`${this.computedProperties.connectionUrl}?query=${encodeURIComponent(queryArg)}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: documents.map(docArg => JSON.stringify(docArg)).join('\n')
|
body: documents.map(docArg => JSON.stringify(docArg)).join('\n'),
|
||||||
|
headers: this.getHeaders()
|
||||||
});
|
});
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getHeaders() {
|
||||||
|
const headers: {[key: string]: string} = {}
|
||||||
|
if (this.options.username) {
|
||||||
|
headers['X-ClickHouse-User'] = this.options.username;
|
||||||
|
}
|
||||||
|
if (this.options.password) {
|
||||||
|
headers['X-ClickHouse-Key'] = this.options.password;
|
||||||
|
}
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,14 @@ import { ClickhouseHttpClient } from './smartclickhouse.classes.httpclient.js';
|
|||||||
export interface IClickhouseConstructorOptions {
|
export interface IClickhouseConstructorOptions {
|
||||||
url: string;
|
url: string;
|
||||||
database: string;
|
database: string;
|
||||||
user?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
|
/**
|
||||||
|
* allow services to exit when waiting for clickhouse startup
|
||||||
|
* this allows to leave the lifecycle flow to other processes
|
||||||
|
* like a listening server.
|
||||||
|
*/
|
||||||
|
unref?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SmartClickHouseDb {
|
export class SmartClickHouseDb {
|
||||||
@ -44,7 +50,7 @@ export class SmartClickHouseDb {
|
|||||||
});
|
});
|
||||||
if (!available) {
|
if (!available) {
|
||||||
console.log(`NOT OK: tried pinging ${this.options.url}... Trying again in 5 seconds.`);
|
console.log(`NOT OK: tried pinging ${this.options.url}... Trying again in 5 seconds.`);
|
||||||
await plugins.smartdelay.delayFor(5000);
|
await plugins.smartdelay.delayFor(5000, null, this.options.unref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,9 @@ export class TimeDataTable {
|
|||||||
* stores a json and tries to map it to the nested syntax
|
* stores a json and tries to map it to the nested syntax
|
||||||
*/
|
*/
|
||||||
public async addData(dataArg: any) {
|
public async addData(dataArg: any) {
|
||||||
|
if (this.healingDeferred) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// the storageJson
|
// the storageJson
|
||||||
let storageJson: { [key: string]: any } = {};
|
let storageJson: { [key: string]: any } = {};
|
||||||
|
Reference in New Issue
Block a user