fix(core): update

This commit is contained in:
2022-03-02 16:35:20 +01:00
parent b8d929f4de
commit ab4ed2602f
7 changed files with 371 additions and 342 deletions

View File

@ -1,26 +1,2 @@
import * as plugins from './smartclickhouse.plugins';
export interface IClickhouseConstructorOptions {
url: string;
port?: number;
}
export class ClickhouseDb {
public options: IClickhouseConstructorOptions;
public clickhouseClient: plugins.clickhouse.ClickHouse;
constructor(optionsArg: IClickhouseConstructorOptions) {
this.options = optionsArg;
}
/**
* starts the connection to the Clickhouse db
*/
public start() {
this.clickhouseClient = new plugins.clickhouse.ClickHouse({
...this.options,
basicAuth: null,
format: 'json'
});
}
}
export * from './smartclickhouse.classes.smartclickhouse';
export * from './smartclickhouse.classes.timedatatable';

View File

@ -0,0 +1,49 @@
import * as plugins from './smartclickhouse.plugins';
import { TimeDataTable } from './smartclickhouse.classes.timedatatable';
export interface IClickhouseConstructorOptions {
host: string;
database: string;
password?: string;
}
export class SmartClickHouseDb {
public options: IClickhouseConstructorOptions;
public clickhouseClient: plugins.clickhouse.ClickHouseClient;
constructor(optionsArg: IClickhouseConstructorOptions) {
this.options = optionsArg;
}
/**
* starts the connection to the Clickhouse db
*/
public async start() {
console.log(`Connecting to default database first.`)
const defaultClient = new plugins.clickhouse.ClickHouseClient({
...this.options,
database: 'default'
});
console.log(`Create database ${this.options.database}, if it does not exist...`);
await defaultClient.queryPromise(`CREATE DATABASE IF NOT EXISTS ${this.options.database}`);
console.log(`Ensured database. Now connecting to wanted database: ${this.options.database}`)
this.clickhouseClient = new plugins.clickhouse.ClickHouseClient({
...this.options,
});
console.log(`trying to ping database...`);
const result = await this.clickhouseClient.ping();
console.log(`Ping successfull?: ${result}`);
}
/**
* gets a table
*/
public async getTable(tableName: string) {
const newTable = TimeDataTable.getTable(this, tableName);
}
}

View File

@ -0,0 +1,20 @@
import * as plugins from './smartclickhouse.plugins';
import { SmartClickHouseDb } from './smartclickhouse.classes.smartclickhouse';
export class TimeDataTable {
public static async getTable(smartClickHouseDbRefArg: SmartClickHouseDb, tableNameArg: string) {
const newTable = new TimeDataTable(smartClickHouseDbRefArg, tableNameArg);
// create table in clickhouse
smartClickHouseDbRefArg;
}
// INSTANCE
public smartClickHouseDbRef: SmartClickHouseDb;
public tableName: string;
constructor(smartClickHouseDbRefArg: SmartClickHouseDb,tableNameArg: string) {
this.smartClickHouseDbRef = smartClickHouseDbRefArg;
this.tableName = tableNameArg;
}
}

View File

@ -1,4 +1,4 @@
import * as clickhouse from 'clickhouse';
import * as clickhouse from '@depyronick/clickhouse-client';
export {
clickhouse