@md03/nestjs-clickhouse
v1.1.0
Published
ClickHouse Nest.js connector module
Downloads
1,125
Maintainers
Readme
ClickHouse module for Nest.js
ClickHouse module based on official client @clickhouse/client
.
Installation
# pnpm:
pnpm add @md03/nestjs-clickhouse @clickhouse/client
# npm:
npm install @md03/nestjs-clickhouse @clickhouse/client
Basic usage
By default module is registered as global (you can change this behavior with isGlobal
parameter).
app.module.ts
import { Module } from '@nestjs/common';
import { ClickHouseModule } from '@md03/nestjs-clickhouse';
@Module({
imports: [
ClickHouseModule.forRoot({
host: 'http://localhost:8123',
username: 'default',
password: '',
}),
ClickHouseModule.forRootAsync({
name: 'conn2'
useFactory: () => ({
host: 'http://localhost:8124',
username: 'default',
password: 'pass123',
}),
}),
],
})
export class AppModule {}
example.service.ts
import { Injectable } from '@nestjs/common';
import { InjectClickHouse } from '@md03/nestjs-clickhouse';
import type { ClickHouseClient } from '@clickhouse/client';
@Injectable()
export class ExampleService {
constructor(
@InjectClickHouse()
private readonly client: ClickHouseClient,
) {}
async getStats() {
const result = await this.client.query(...);
}
}
Common problems
ReferenceError: ClickHouseClient is not defined
- Make sure you have
@clickhouse/client
installed along side@md03/nestjs-clickhouse
(this module requires client as peer dependency) - Import as type instead class
import type { ClickHouseClient } from '@clickhouse/client';