4 Commits

7 changed files with 27 additions and 20 deletions

6
changelog.md Normal file
View File

@ -0,0 +1,6 @@
# Changelog
## 2.1.0 - feat(core): Added comprehensive support for `SmartClickHouseDb` and `TimeDataTable` with features including time data table creation, data insertion, bulk data insertion, querying, data deletion, and real-time data observation. Included standalone Clickhouse HTTP client implementation.
### Fixed
- Fixed test case for table deletion and optimized code

View File

@ -1,4 +1,4 @@
Copyright (c) 2022 Lossless GmbH (hello@lossless.com) Copyright (c) 2022 Task Venture Capital GmbH (hello@task.vc)
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@push.rocks/smartclickhouse", "name": "@push.rocks/smartclickhouse",
"version": "2.0.17", "version": "2.1.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@push.rocks/smartclickhouse", "name": "@push.rocks/smartclickhouse",
"version": "2.0.17", "version": "2.1.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@push.rocks/smartdelay": "^2.0.13", "@push.rocks/smartdelay": "^2.0.13",

View File

@ -1,6 +1,6 @@
{ {
"name": "@push.rocks/smartclickhouse", "name": "@push.rocks/smartclickhouse",
"version": "2.0.17", "version": "2.1.0",
"private": false, "private": false,
"description": "A TypeScript-based ODM for ClickHouse databases that supports creating, managing, and querying tables with a focus on handling time-series data.", "description": "A TypeScript-based ODM for ClickHouse databases that supports creating, managing, and querying tables with a focus on handling time-series data.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

View File

@ -72,16 +72,6 @@ tap.test('should delete old entries', async (toolsArg) => {
await toolsArg.delayFor(5000); await toolsArg.delayFor(5000);
}); });
tap.test('should delete the table', async () => {
await table.delete();
// Verify table deletion
const result = await testClickhouseDb.clickhouseHttpClient.queryPromise(`
SHOW TABLES FROM ${testClickhouseDb.options.database} LIKE '${table.options.tableName}'
`);
console.log('Table exists after deletion:', result);
expect(result.length).toEqual(0);
});
tap.test('should stream new entries', async (toolsArg) => { tap.test('should stream new entries', async (toolsArg) => {
const stream = table.watchNewEntries(); const stream = table.watchNewEntries();
const subscription = stream.subscribe((entry) => { const subscription = stream.subscribe((entry) => {
@ -101,4 +91,14 @@ tap.test('should stream new entries', async (toolsArg) => {
subscription.unsubscribe(); subscription.unsubscribe();
}); });
tap.test('should delete the table', async () => {
await table.delete();
// Verify table deletion
const result = await testClickhouseDb.clickhouseHttpClient.queryPromise(`
SHOW TABLES FROM ${testClickhouseDb.options.database} LIKE '${table.options.tableName}'
`);
console.log('Table exists after deletion:', result);
expect(result.length).toEqual(0);
});
export default tap.start(); export default tap.start();

View File

@ -1,8 +1,8 @@
/** /**
* autocreated commitinfo by @pushrocks/commitinfo * autocreated commitinfo by @push.rocks/commitinfo
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartclickhouse', name: '@push.rocks/smartclickhouse',
version: '2.0.17', version: '2.1.0',
description: 'A TypeScript-based ODM for ClickHouse databases that supports creating, managing, and querying tables with a focus on handling time-series data.' description: 'A TypeScript-based ODM for ClickHouse databases that supports creating, managing, and querying tables with a focus on handling time-series data.'
} }

View File

@ -270,6 +270,7 @@ export class TimeDataTable {
return new plugins.smartrx.rxjs.Observable((observer) => { return new plugins.smartrx.rxjs.Observable((observer) => {
const pollInterval = 1000; // Poll every 1 second const pollInterval = 1000; // Poll every 1 second
let lastTimestamp: number; let lastTimestamp: number;
let intervalId: NodeJS.Timeout;
const fetchLastEntryTimestamp = async () => { const fetchLastEntryTimestamp = async () => {
const lastEntry = await this.smartClickHouseDbRef.clickhouseHttpClient.queryPromise(` const lastEntry = await this.smartClickHouseDbRef.clickhouseHttpClient.queryPromise(`
@ -292,13 +293,13 @@ export class TimeDataTable {
const startPolling = async () => { const startPolling = async () => {
await fetchLastEntryTimestamp(); await fetchLastEntryTimestamp();
const intervalId = setInterval(fetchNewEntries, pollInterval); intervalId = setInterval(fetchNewEntries, pollInterval);
// Cleanup on unsubscribe
return () => clearInterval(intervalId);
}; };
startPolling().catch((err) => observer.error(err)); startPolling().catch((err) => observer.error(err));
// Cleanup on unsubscribe
return () => clearInterval(intervalId);
}); });
} }
} }