diff --git a/examples/common_nestjs_remix/apps/api/src/health/health.controller.ts b/examples/common_nestjs_remix/apps/api/src/health/health.controller.ts index be94f54..63b1ee5 100644 --- a/examples/common_nestjs_remix/apps/api/src/health/health.controller.ts +++ b/examples/common_nestjs_remix/apps/api/src/health/health.controller.ts @@ -3,9 +3,9 @@ import { HealthCheckService, HttpHealthIndicator, HealthCheck, - TypeOrmHealthIndicator, } from "@nestjs/terminus"; import { Public } from "src/common/decorators/public.decorator"; +import { DrizzleOrmHealthIndicator } from "./indicator/database/drizzleorm.health"; @Controller("health") export class HealthController { diff --git a/examples/common_nestjs_remix/apps/api/src/health/health.module.ts b/examples/common_nestjs_remix/apps/api/src/health/health.module.ts index d423f6d..4ba7a20 100644 --- a/examples/common_nestjs_remix/apps/api/src/health/health.module.ts +++ b/examples/common_nestjs_remix/apps/api/src/health/health.module.ts @@ -2,9 +2,11 @@ import { Module } from "@nestjs/common"; import { TerminusModule } from "@nestjs/terminus"; import { HttpModule } from "@nestjs/axios"; import { HealthController } from "./health.controller"; +import { DrizzleOrmHealthIndicator } from "./indicator/database/drizzleorm.health"; @Module({ imports: [TerminusModule, HttpModule], + providers: [DrizzleOrmHealthIndicator], controllers: [HealthController], }) export class HealthModule {} diff --git a/examples/common_nestjs_remix/apps/api/src/health/indicator/database/drizzleorm.health.ts b/examples/common_nestjs_remix/apps/api/src/health/indicator/database/drizzleorm.health.ts new file mode 100644 index 0000000..a7e9276 --- /dev/null +++ b/examples/common_nestjs_remix/apps/api/src/health/indicator/database/drizzleorm.health.ts @@ -0,0 +1,26 @@ +import { Inject, Injectable } from "@nestjs/common"; +import { + HealthIndicator, + HealthIndicatorResult, + HealthCheckError, +} from "@nestjs/terminus"; +import { sql } from "drizzle-orm"; +import { DatabasePg } from "src/common"; + +@Injectable() +export class DrizzleOrmHealthIndicator extends HealthIndicator { + constructor(@Inject("DB") private readonly db: DatabasePg) { + super(); + } + + async pingCheck(key: string): Promise { + try { + await this.db.execute(sql`SELECT 1`); + + return this.getStatus(key, true); + } catch (error) { + const result = this.getStatus(key, false); + throw new HealthCheckError("Database check failed", result); + } + } +}