MCPcopy Create free account
hub / github.com/prisma/prisma-examples / prismaClientSingleton

Function prismaClientSingleton

orm/nuxt-prisma-module/lib/prisma.ts:4–22  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { PrismaPg } from '@prisma/adapter-pg'
3
4const 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
24declare const globalThis: {
25 prismaGlobal: ReturnType<typeof prismaClientSingleton>

Callers 1

prisma.tsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected