© 2026 Hedgehog Software, LLC
generator client { provider = "prisma-client-js" previewFeatures = ["multiSchema", "prismaSchemaFolder", "views", "tracing"] } datasource db { provider = "postgresql" url = env("DATABASE_URL") schemas = [LIST_OF_SCHEMA_HERE ie: 'a', 'b' ...] }
import { PrismaClient } from '@prisma/client' import { withOptimize } from '@prisma/extension-optimize' import { withPulse } from '@prisma/extension-pulse' function extendClient( base: PrismaClient, ): PrismaClient & ReturnType<typeof withPulse> & ReturnType<typeof withOptimize> { const extended = base .$extends( withOptimize({ apiKey: process.env.OPTIMIZE_API_KEY as string, }), ) .$extends( withPulse({ apiKey: process.env.PULSE_API_KEY as string, }), ) as unknown as PrismaClient & ReturnType<typeof withPulse> & ReturnType<typeof withOptimize> return extended } export class UntypedExtendedClient extends PrismaClient { constructor(options?: ConstructorParameters<typeof PrismaClient>[0]) { super(options) // biome-ignore lint/correctness/noConstructorReturn: Extended client is returned return extendClient(this) as PrismaClient & ReturnType<typeof withPulse> & ReturnType<typeof withOptimize> } } export const ExtendedPrismaClient = UntypedExtendedClient as unknown as new ( options?: ConstructorParameters<typeof PrismaClient>[0], ) => ReturnType<typeof extendClient> export type ExtendedPrismaClientType = ReturnType<typeof extendClient>
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common' import { ExtendedPrismaClient } from './prisma.extension' @Injectable() export class PrismaService extends ExtendedPrismaClient implements OnModuleInit, OnModuleDestroy { private static instance: PrismaService | null = null constructor() { super({ datasources: { db: { url: process.env.DATABASE_URL, }, }, log: ['error', 'warn'], }) if (PrismaService.instance) { // biome-ignore lint/correctness/noConstructorReturn: <We don't want to create a new instance> return PrismaService.instance } PrismaService.instance = this } async onModuleInit() { await this.$connect() } async onModuleDestroy() { await this.$disconnect() } }