Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
26449e9171 | |||
c91b7a200b | |||
fde082974f | |||
84c355c499 | |||
367bacb954 | |||
2adbed8fdb |
6
changelog.md
Normal file
6
changelog.md
Normal 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
|
2
license
2
license
@ -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
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"githost": "code.foss.global",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "push.rocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartclickhouse",
|
"gitrepo": "smartclickhouse",
|
||||||
"description": "A TypeScript-based ODM (Object-Document Mapper) for ClickHouse databases, with support for creating and managing tables and 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.",
|
||||||
"npmPackagename": "@push.rocks/smartclickhouse",
|
"npmPackagename": "@push.rocks/smartclickhouse",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks",
|
"projectDomain": "push.rocks",
|
||||||
@ -22,7 +22,13 @@
|
|||||||
"data storage",
|
"data storage",
|
||||||
"time-series data",
|
"time-series data",
|
||||||
"schema management",
|
"schema management",
|
||||||
"data insertion"
|
"data insertion",
|
||||||
|
"real-time data",
|
||||||
|
"data querying",
|
||||||
|
"bulk data insertion",
|
||||||
|
"error handling",
|
||||||
|
"data deletion",
|
||||||
|
"observables"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartclickhouse",
|
"name": "@push.rocks/smartclickhouse",
|
||||||
"version": "2.0.16",
|
"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.16",
|
"version": "2.1.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/smartdelay": "^2.0.13",
|
"@push.rocks/smartdelay": "^2.0.13",
|
||||||
|
12
package.json
12
package.json
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartclickhouse",
|
"name": "@push.rocks/smartclickhouse",
|
||||||
"version": "2.0.16",
|
"version": "2.1.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "A TypeScript-based ODM (Object-Document Mapper) for ClickHouse databases, with support for creating and managing tables and 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",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@ -61,7 +61,13 @@
|
|||||||
"data storage",
|
"data storage",
|
||||||
"time-series data",
|
"time-series data",
|
||||||
"schema management",
|
"schema management",
|
||||||
"data insertion"
|
"data insertion",
|
||||||
|
"real-time data",
|
||||||
|
"data querying",
|
||||||
|
"bulk data insertion",
|
||||||
|
"error handling",
|
||||||
|
"data deletion",
|
||||||
|
"observables"
|
||||||
],
|
],
|
||||||
"homepage": "https://code.foss.global/push.rocks/smartclickhouse",
|
"homepage": "https://code.foss.global/push.rocks/smartclickhouse",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
13
readme.md
13
readme.md
@ -1,7 +1,6 @@
|
|||||||
```markdown
|
|
||||||
# @push.rocks/smartclickhouse
|
# @push.rocks/smartclickhouse
|
||||||
|
|
||||||
A TypeScript-based ODM (Object-Document Mapper) for ClickHouse databases, with support for creating and managing tables and their data.
|
A TypeScript-based ODM (Object-Document Mapper) for ClickHouse databases, with support for creating and managing tables and handling time-series data.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
@ -21,7 +20,7 @@ This will add the package to your project's dependencies.
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
`@push.rocks/smartclickhouse` is an ODM (Object Document Mapper) module specifically designed for interacting with ClickHouse databases efficiently and effectively. Leveraging TypeScript, it offers strong typing and intelligent code completion, making database operations more intuitive and less error-prone.
|
`@push.rocks/smartclickhouse` is an advanced ODM (Object Document Mapper) module designed for seamless interaction with ClickHouse databases leveraging the capabilities of TypeScript for strong typing and enhanced developer experience. Below is a comprehensive guide to using the package in various scenarios.
|
||||||
|
|
||||||
### Setting Up and Starting the Connection
|
### Setting Up and Starting the Connection
|
||||||
|
|
||||||
@ -36,7 +35,7 @@ const dbInstance = new SmartClickHouseDb({
|
|||||||
database: 'yourDatabase', // Database name you want to connect to
|
database: 'yourDatabase', // Database name you want to connect to
|
||||||
username: 'default', // Optional: Username for authentication
|
username: 'default', // Optional: Username for authentication
|
||||||
password: 'password', // Optional: Password for authentication
|
password: 'password', // Optional: Password for authentication
|
||||||
unref: true // Optional: Allows service to exit while awaiting database startup
|
unref: true // Optional: Allows service to exit while awaiting database startup
|
||||||
});
|
});
|
||||||
|
|
||||||
// Start the instance to establish the connection
|
// Start the instance to establish the connection
|
||||||
@ -73,7 +72,7 @@ The `addData` method is designed to be flexible, allowing insertion of various d
|
|||||||
|
|
||||||
### Advanced Usage and Custom Data Handling
|
### Advanced Usage and Custom Data Handling
|
||||||
|
|
||||||
`smartclickhouse` supports custom data types and complex data structures. For instance, to add support for nested objects or custom data processing before insertion, you might need to extend existing classes or contribute to the module development for broader use cases.
|
`smartclickhouse` supports custom data types and complex data structures. For instance, to add support for nested objects or custom data processing before insertion, you might need to extend existing classes or customize the `addData` method to fit your needs.
|
||||||
|
|
||||||
#### Custom Data Processing
|
#### Custom Data Processing
|
||||||
|
|
||||||
@ -193,7 +192,7 @@ console.log('Table exists after deletion:', result.length === 0);
|
|||||||
To observe new entries in real-time, you can stream new data entries using the RxJS Observable:
|
To observe new entries in real-time, you can stream new data entries using the RxJS Observable:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const stream = table.streamNewEntries();
|
const stream = table.watchNewEntries();
|
||||||
|
|
||||||
const subscription = stream.subscribe((entry) => {
|
const subscription = stream.subscribe((entry) => {
|
||||||
console.log('New entry:', entry);
|
console.log('New entry:', entry);
|
||||||
@ -237,8 +236,6 @@ To contribute:
|
|||||||
|
|
||||||
The above scenarios cover the essential functionality and the more advanced use cases of `@push.rocks/smartclickhouse`, providing a comprehensive guide to utilizing the module into your projects. Happy coding!
|
The above scenarios cover the essential functionality and the more advanced use cases of `@push.rocks/smartclickhouse`, providing a comprehensive guide to utilizing the module into your projects. Happy coding!
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## License and Legal Information
|
## License and Legal Information
|
||||||
|
|
||||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||||
|
@ -72,18 +72,8 @@ 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.streamNewEntries();
|
const stream = table.watchNewEntries();
|
||||||
const subscription = stream.subscribe((entry) => {
|
const subscription = stream.subscribe((entry) => {
|
||||||
console.log('New entry:', entry);
|
console.log('New entry:', 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();
|
@ -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.16',
|
version: '2.1.0',
|
||||||
description: 'A TypeScript-based ODM (Object-Document Mapper) for ClickHouse databases, with support for creating and managing tables and 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.'
|
||||||
}
|
}
|
||||||
|
@ -266,10 +266,11 @@ export class TimeDataTable {
|
|||||||
/**
|
/**
|
||||||
* streams all new entries using an observable
|
* streams all new entries using an observable
|
||||||
*/
|
*/
|
||||||
public streamNewEntries(): plugins.smartrx.rxjs.Observable<any> {
|
public watchNewEntries(): plugins.smartrx.rxjs.Observable<any> {
|
||||||
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user