| 2 | import { PrismaPg } from '@prisma/adapter-pg' |
| 3 | |
| 4 | const prismaClientSingleton = () => { |
| 5 | |
| 6 | // Custom extended Prisma ORM instance with client extensions, adding a method to verify the existence of a database entry. |
| 7 | const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! }) |
| 8 | return new PrismaClient({ adapter: pool }).$extends({ |
| 9 | model: { |
| 10 | $allModels: { |
| 11 | async exists<T>( |
| 12 | this: T, |
| 13 | where: Prisma.Args<T, 'findFirst'>['where'], |
| 14 | ): Promise<boolean> { |
| 15 | const context = Prisma.getExtensionContext(this) |
| 16 | const result = await (context as any).findFirst({ where }) |
| 17 | return result !== null |
| 18 | }, |
| 19 | }, |
| 20 | }, |
| 21 | }) |
| 22 | } |
| 23 | |
| 24 | declare const globalThis: { |
| 25 | prismaGlobal: ReturnType<typeof prismaClientSingleton> |