Skip to content

Commit

Permalink
fix(mikro-orm.health): mikro-orm connection type is deprecated
Browse files Browse the repository at this point in the history
Use the abstraction provided by MikroOrm to determine connection status.
resolves #2325
  • Loading branch information
StefanPrintezis authored and BrunnerLivio committed Sep 14, 2023
1 parent 7a15d89 commit 1c0eff9
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions lib/health-indicator/database/mikro-orm.health.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -121,24 +121,7 @@ export class MikroOrmHealthIndicator extends HealthIndicator {
*
*/
private async pingDb(connection: MikroOrm.Connection, timeout: number) {
let check: Promise<any>;
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);
}
}

0 comments on commit 1c0eff9

Please sign in to comment.