2 Commits

Author SHA1 Message Date
fbf177b482 2.0.6 2022-07-27 23:11:03 +02:00
3272b87e10 fix(core): update 2022-07-27 23:11:03 +02:00
4 changed files with 32 additions and 27 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@pushrocks/smartclickhouse", "name": "@pushrocks/smartclickhouse",
"version": "2.0.5", "version": "2.0.6",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@pushrocks/smartclickhouse", "name": "@pushrocks/smartclickhouse",
"version": "2.0.5", "version": "2.0.6",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@depyronick/clickhouse-client": "^1.0.14", "@depyronick/clickhouse-client": "^1.0.14",

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartclickhouse", "name": "@pushrocks/smartclickhouse",
"version": "2.0.5", "version": "2.0.6",
"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",

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@pushrocks/smartclickhouse', name: '@pushrocks/smartclickhouse',
version: '2.0.5', version: '2.0.6',
description: 'an odm for talking to clickhouse' description: 'an odm for talking to clickhouse'
} }

View File

@ -38,29 +38,7 @@ export class TimeDataTable {
retainDataForDays: 30 retainDataForDays: 30
}); });
// create table in clickhouse await newTable.setup();
await smartClickHouseDbRefArg.clickhouseClient
.queryPromise(`
CREATE TABLE IF NOT EXISTS ${newTable.options.tableName} (
timestamp DateTime64(3, 'Europe/Berlin'),
message String
) ENGINE=MergeTree() ORDER BY timestamp`);
// lets adjust the TTL
await smartClickHouseDbRefArg.clickhouseClient
.queryPromise(`
ALTER TABLE ${newTable.options.tableName} MODIFY TTL toDateTime(timestamp) + INTERVAL ${newTable.options.retainDataForDays} DAY
`);
await newTable.updateColumns();
console.log(`=======================`)
console.log(
`table with name "${newTable.options.tableName}" in databse ${newTable.smartClickHouseDbRef.options.database} has the following columns:`
);
for (const column of newTable.columns) {
console.log(`>> ${column.name}: ${column.type}`);
}
console.log('^^^^^^^^^^^^^^\n');
return newTable; return newTable;
} }
@ -75,6 +53,32 @@ export class TimeDataTable {
this.options = optionsArg; this.options = optionsArg;
} }
public async setup() {
// create table in clickhouse
await this.smartClickHouseDbRef.clickhouseClient
.queryPromise(`
CREATE TABLE IF NOT EXISTS ${this.options.tableName} (
timestamp DateTime64(3, 'Europe/Berlin'),
message String
) ENGINE=MergeTree() ORDER BY timestamp`);
// lets adjust the TTL
await this.smartClickHouseDbRef.clickhouseClient
.queryPromise(`
ALTER TABLE ${this.options.tableName} MODIFY TTL toDateTime(timestamp) + INTERVAL ${this.options.retainDataForDays} DAY
`);
await this.updateColumns();
console.log(`=======================`)
console.log(
`table with name "${this.options.tableName}" in database ${this.smartClickHouseDbRef.options.database} has the following columns:`
);
for (const column of this.columns) {
console.log(`>> ${column.name}: ${column.type}`);
}
console.log('^^^^^^^^^^^^^^\n');
}
public columns: IColumnInfo[] = []; public columns: IColumnInfo[] = [];
/** /**
@ -174,6 +178,7 @@ export class TimeDataTable {
console.log(`Ran into an error. Trying to set up things properly again.`); console.log(`Ran into an error. Trying to set up things properly again.`);
await this.smartClickHouseDbRef.pingDatabaseUntilAvailable(); await this.smartClickHouseDbRef.pingDatabaseUntilAvailable();
await this.smartClickHouseDbRef.createDatabase(); await this.smartClickHouseDbRef.createDatabase();
await this.setup();
this.columns = []; this.columns = [];
this.healingDeferred.resolve(); this.healingDeferred.resolve();
this.healingDeferred = null; this.healingDeferred = null;