A TypeScript-based ODM (Object-Document Mapper) for ClickHouse databases, with support for creating and managing tables and their data.
Go to file
2024-06-14 16:33:00 +02:00
.gitea/workflows fix(core): update 2024-06-14 16:33:00 +02:00
.vscode fix(core): update 2022-08-05 13:31:11 +02:00
test fix(core): update 2024-06-14 16:33:00 +02:00
ts fix(core): update 2024-06-14 16:33:00 +02:00
.gitignore fix(core): update 2022-03-01 15:03:55 +01:00
license fix(core): update 2022-03-01 15:03:55 +01:00
npmextra.json update tsconfig 2024-04-14 17:25:03 +02:00
package-lock.json fix(core): update 2024-06-14 16:33:00 +02:00
package.json fix(core): update 2024-06-14 16:33:00 +02:00
pnpm-lock.yaml fix(core): update 2024-06-14 16:33:00 +02:00
readme.hints.md fix(core): update 2024-06-14 16:33:00 +02:00
readme.md update tsconfig 2024-04-14 17:25:03 +02:00
tsconfig.json update npmextra.json: githost 2024-04-01 21:34:13 +02:00

@push.rocks/smartclickhouse

an odm for talking to clickhouse

Install

To install @push.rocks/smartclickhouse, use the following command with npm:

npm install @push.rocks/smartclickhouse --save

Or with yarn:

yarn add @push.rocks/smartclickhouse

This will add the package to your project's dependencies.

Usage

@push.rocks/smartclickhouse is an ORM (Object Relational Mapping) 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.

Setting Up and Starting the Connection

First, you need to establish a connection with the ClickHouse database. This involves creating an instance of SmartClickHouseDb and starting it:

import { SmartClickHouseDb } from '@push.rocks/smartclickhouse';

// Create a new instance of SmartClickHouseDb with your ClickHouse database details
const dbInstance = new SmartClickHouseDb({
  url: 'http://localhost:8123', // URL of ClickHouse instance
  database: 'yourDatabase',     // Database name you want to connect
  username: 'default',          // Optional: Username for authentication
  password: 'password',         // Optional: Password for authentication
  unref: true                    // Optional: Allows service to exit while awaiting database startup
});

// Start the instance to establish the connection
await dbInstance.start();

Working with Time Data Tables

smartclickhouse allows handling of time-series data through TimeDataTable, automating tasks such as table creation and data insertion.

Creating or Accessing a Table

To create a new time data table or access an existing one:

const tableName = 'yourTimeDataTable'; // Name of the table you want to access or create
const table = await dbInstance.getTable(tableName);

Adding Data to the Table

Once you have the table instance, you can insert data into it:

await table.addData({
  timestamp: Date.now(),       // Timestamp in milliseconds
  message: 'A log message.',   // Arbitrary data field
  temperature: 22.5,           // Another example field
  tags: ['tag1', 'tag2']       // An example array field
});

addData method is designed to be flexible, allowing insertion of various data types and automatically managing table schema adjustments.

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 module development for broader use cases.

Complete Feature Set Overview

While the above examples cover basic usage, @push.rocks/smartclickhouse offers a wide range of functionalities, including but not limited to:

  • Robust error handling and reconnection strategies
  • Efficient bulk data insertion mechanisms
  • Support for ClickHouse specific features like materialized views and aggregating MergeTree engines
  • Techniques for managing and querying large time-series datasets

For a comprehensive guide on leveraging all @push.rocks/smartclickhouse features, consult the module documentation and examples. Engage with the community for tips on advanced use cases and optimization strategies for handling time-series data with ClickHouse.

Contribution

Contributions to @push.rocks/smartclickhouse are welcome. Whether it's through submitting issues, proposing improvements, or adding to the codebase, your input is valuable. The project is designed to be open and accessible, striving for a high-quality, community-driven development process.

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 file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.