fix(core): update
This commit is contained in:
28
ts/index.ts
28
ts/index.ts
@ -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';
|
||||
|
49
ts/smartclickhouse.classes.smartclickhouse.ts
Normal file
49
ts/smartclickhouse.classes.smartclickhouse.ts
Normal 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);
|
||||
}
|
||||
}
|
20
ts/smartclickhouse.classes.timedatatable.ts
Normal file
20
ts/smartclickhouse.classes.timedatatable.ts
Normal 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;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import * as clickhouse from 'clickhouse';
|
||||
import * as clickhouse from '@depyronick/clickhouse-client';
|
||||
|
||||
export {
|
||||
clickhouse
|
||||
|
Reference in New Issue
Block a user