I’d like to create a health check endpoint if pris...
# orm-help
d
I’d like to create a health check endpoint if prisma is connected with my backend server(Nodejs or NestJS). Anyone has good idea on this?
r
@Dante 👋 Would you be exposing this endpoint to your load balancer?
d
@Ryan Hi, Ryan. I am thinking about this in experimental level. Let’s say I have Jest unit tests and one of them is to check if prisma is connected to backend. I’d like to confirm prisma has no problem with connecting be before runtime. I am using nestJS and thinking to use
onMoudleInit()
. any kind advice?
Copy code
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
  async onModuleInit() {
    await this.$connect();
  }

  async enableShutdownHooks(app: INestApplication) {
    this.$on('beforeExit', async () => {
      await app.close();
    });
  }
}
I solved this problem as written below
Copy code
const result = await prismaService.$queryRaw`SELECT 1`;
      expect(result).toEqual([{ '?column?': 1 }]);