smartlog-destination-clickh.../ts/index.ts

27 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-07-26 11:43:23 +00:00
import * as plugins from './slclick.plugins.js';
export class SmartlogDestinationClickhouse implements plugins.smartlogInterfaces.ILogDestination {
// STATIC
public static async createAndStart(optionsArg: plugins.smartclickhouse.IClickhouseConstructorOptions) {
const destinationClickhouse = new SmartlogDestinationClickhouse(optionsArg);
await destinationClickhouse.start();
return destinationClickhouse;
}
// INSTANCE
private smartclickhouseDb: plugins.smartclickhouse.SmartClickHouseDb;
private logTable: plugins.smartclickhouse.TimeDataTable;
constructor(options: plugins.smartclickhouse.IClickhouseConstructorOptions) {
this.smartclickhouseDb = new plugins.smartclickhouse.SmartClickHouseDb(options);
}
public async start() {
await this.smartclickhouseDb.start();
this.logTable = await this.smartclickhouseDb.getTable('logs');
}
public async handleLog(logPackage: plugins.smartlogInterfaces.ILogPackage<unknown>): Promise<void> {
await this.logTable.addData(logPackage);
};
}