18 lines
393 B
TypeScript
18 lines
393 B
TypeScript
import { PrismaClient } from '@prisma/client'
|
|
import { env } from '@/lib/utils'
|
|
|
|
const prismaClientSingleton = () => {
|
|
return new PrismaClient()
|
|
}
|
|
|
|
declare global {
|
|
var prismaGlobal: undefined | ReturnType<typeof prismaClientSingleton>
|
|
}
|
|
|
|
const db = globalThis.prismaGlobal ?? prismaClientSingleton()
|
|
|
|
export default db
|
|
|
|
if (env('NODE_ENV') !== 'production') globalThis.prismaGlobal = db
|
|
|