NestJS Profiler
API Reference

nest-profiler-typeorm

Types and API of the TypeORM query collector.

TypeOrmCollectorModuleOptions

Options passed to TypeOrmCollectorModule.forRoot().

Prop

Type

QueryEntry

One entry per SQL query executed during a request.

Prop

Type

QueryType

type QueryType = 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'OTHER';

Detected from the first keyword of the SQL string.

Public exports

import { TypeOrmCollectorModule } from '@eleven-labs/nest-profiler-typeorm';
import { TypeOrmCollector } from '@eleven-labs/nest-profiler-typeorm';

import type {
  TypeOrmCollectorModuleOptions,
  TypeOrmCollectorModuleAsyncOptions,
  QueryEntry,
  QueryType,
} from '@eleven-labs/nest-profiler-typeorm';

Setup

// In ProductsModule (or any module that uses TypeORM):
TypeOrmCollectorModule.forRoot({
  slowThreshold: 50, // ms — queries at/above this are tagged 'slow'
});

Prerequisite: TypeOrmModule.forRoot() must be registered in the application (provides DataSource globally via @InjectDataSource()).

Async setup

Drive the options from ConfigService (or any provider) with forRootAsync(), gated per environment with ConditionalModule (recommended). It resolves option values only — for the enabled flag and when to prefer forRoot, see Enabling and disabling the profiler.

import { ConditionalModule, ConfigService } from '@nestjs/config';
import { TypeOrmCollectorModule } from '@eleven-labs/nest-profiler-typeorm';

const isProfilerEnabled = (env: NodeJS.ProcessEnv) => env['PROFILER_ENABLED'] !== 'false';

ConditionalModule.registerWhen(
  TypeOrmCollectorModule.forRootAsync({
    inject: [ConfigService],
    useFactory: (config: ConfigService) => ({
      slowThreshold: config.get<number>('PROFILER_SLOW_QUERY_MS') ?? 50,
    }),
  }),
  isProfilerEnabled,
);
Powered & maintained by

On this page