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",
"version": "2.0.5",
"version": "2.0.6",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@pushrocks/smartclickhouse",
"version": "2.0.5",
"version": "2.0.6",
"license": "MIT",
"dependencies": {
"@depyronick/clickhouse-client": "^1.0.14",

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartclickhouse",
"version": "2.0.5",
"version": "2.0.6",
"private": false,
"description": "an odm for talking to clickhouse",
"main": "dist_ts/index.js",

View File

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

View File

@ -38,29 +38,7 @@ export class TimeDataTable {
retainDataForDays: 30
});
// create table in clickhouse
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');
await newTable.setup();
return newTable;
}
@ -75,6 +53,32 @@ export class TimeDataTable {
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[] = [];
/**
@ -174,6 +178,7 @@ export class TimeDataTable {
console.log(`Ran into an error. Trying to set up things properly again.`);
await this.smartClickHouseDbRef.pingDatabaseUntilAvailable();
await this.smartClickHouseDbRef.createDatabase();
await this.setup();
this.columns = [];
this.healingDeferred.resolve();
this.healingDeferred = null;