NestJS for clickhouse based on zimv/node-clickhouse-orm
npm install @oneralon/nestjs-clickhouseThe package based on https://github.com/zimv/node-clickhouse-orm
```
npm i --save @oneralon/nestjs-clickhouse
`
import { ClickHouseModule } from '@oneralon/nestjs-clickhouse';
@Module({
imports: [
ClickHouseModule.forRoot({
url: 'http://clickhouse.host',
port: 8123,
username: 'default',
password: 'password',
database: 'default',
debug: true,
useGzip: true,
format: 'json', // 'json' | 'csv' | 'tsv'
}),
...
]
})
...
`
`
import { DataType, Model, Prop, Schema } from '@oneralon/nestjs-clickhouse';
@Schema({
tableName: 'entities',
options: 'ENGINE = MergeTree ORDER BY field1',
})
export class Entity {
@Prop({
type: DataType.String,
})
public field1: string;
@Prop({
type: DataType.Int64,
})
public field2: number;
@Prop({
type: DataType.String,
get: (value: string) => JSON.parse(value),
set: (value: object) => JSON.stringify(value),
})
public field3: { a: number, b: string };
}
export type EntityModel = Model
`
`
import { ClickHouseModule } from '@oneralon/nestjs-clickhouse';
@Module({
imports: [
ClickHouseModule.forFeature([
Entity,
]),
...
]
})
...
`
`
class EntitiesService {
@Inject(Entity.name)
private readonly model: EntityModel;
public async create(value: Entity) {
await this.model.create(value);
}
...
}
``