From e3314a027aa5e18d975cad7e9a9b6763cf027bb6 Mon Sep 17 00:00:00 2001 From: Stefan Printezis Date: Wed, 9 Aug 2023 18:20:20 +0200 Subject: [PATCH] fix(mikro-orm.health): mikro-orm connection `type` is deprecated Use the abstraction provided by MikroOrm to determine connection status. --- .../database/mikro-orm.health.ts | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/lib/health-indicator/database/mikro-orm.health.ts b/lib/health-indicator/database/mikro-orm.health.ts index 48e3bfc1b..10d578997 100644 --- a/lib/health-indicator/database/mikro-orm.health.ts +++ b/lib/health-indicator/database/mikro-orm.health.ts @@ -1,6 +1,6 @@ -import { Injectable, NotImplementedException, Scope } from '@nestjs/common'; +import { Injectable, Scope } from '@nestjs/common'; import { ModuleRef } from '@nestjs/core'; -import { HealthCheckError } from '../../health-check/health-check.error'; +import { HealthCheckError } from '../../health-check'; import * as MikroOrm from '@mikro-orm/core'; import { TimeoutError } from '../../errors'; @@ -121,24 +121,7 @@ export class MikroOrmHealthIndicator extends HealthIndicator { * */ private async pingDb(connection: MikroOrm.Connection, timeout: number) { - let check: Promise; - const type = connection.getPlatform().getConfig().get('type'); - - switch (type) { - case 'postgresql': - case 'mysql': - case 'mariadb': - case 'sqlite': - check = connection.execute('SELECT 1'); - break; - case 'mongo': - check = connection.isConnected(); - break; - default: - throw new NotImplementedException( - `${type} ping check is not implemented yet`, - ); - } - return await promiseTimeout(timeout, check); + const isConnected = connection.isConnected(); + return await promiseTimeout(timeout, isConnected); } }