nest-influxdb-compat
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

npm version downloads issues

Description

InfluxDB module for Nest based on the official InfluxDb package.

Installation

npm install nest-influxdb --save

or

yarn add nest-influxdb

Usage

Register module:

import { Module } from "@nestjs/common";
import { InfluxDbModule, InfluxModuleOptions } from "nest-influxdb";
import { UtilsModule } from "./utils/utils.module";
import { ConfigService } from "./utils/config/config.service";

@Module({
    imports: [
        InfluxDbModule.forRootAsync({
            imports: [UtilsModule],
            inject: [ConfigService],
            useFactory: async (
                config_servie: ConfigService
            ): Promise<InfluxModuleOptions> => {
                return {
                    host: config_servie.get("INFLUX_HOST")
                };
            }
        }),
        TrafficModule
    ],
    controllers: [AppController],
    providers: [AppService]
})
export class AppModule {}

Get access to InfluxDbService in some your service:

@Injectable()
export class TrafficService {
    constructor(private readonly influx_service: InfluxDbService) {}

    public async getLastDay(): Promise<ResponseDto> {
        const results = await this.influx_service.query(`
            select MEAN(*) from traffic WHERE time > now() - 1d GROUP BY time(10m);
        `);

        return results.map(pointToDto);
    }
}

Package Sidebar

Install

npm i nest-influxdb-compat

Weekly Downloads

2

Version

0.0.5

License

MIT

Unpacked Size

46.9 kB

Total Files

21

Last publish

Collaborators

  • upscripter