P
Prisma2mo ago
berry73

Why does this function not work?

I'm trying to create a prisma file (/lib/db.ts) to initialize from anywhere in my code when I need it. Why does $disccount and $use not work and how do i get it to work if it is necessary. Here is code:
import { PrismaClient, Prisma } from '@prisma/client'
import { handleConnectionError } from '@/middleware'

const prisma = global.prisma || new PrismaClient()

if (process.env.NODE_ENV === 'production') {
global.prisma = prisma
}

const prismaWithEvents = prisma as Prisma.PrismaClient
prismaWithEvents.$on('beforeExit', async() => {
await prisma.$disconnect()
})

prisma.$use(handleConnectionError)

export default prisma
import { PrismaClient, Prisma } from '@prisma/client'
import { handleConnectionError } from '@/middleware'

const prisma = global.prisma || new PrismaClient()

if (process.env.NODE_ENV === 'production') {
global.prisma = prisma
}

const prismaWithEvents = prisma as Prisma.PrismaClient
prismaWithEvents.$on('beforeExit', async() => {
await prisma.$disconnect()
})

prisma.$use(handleConnectionError)

export default prisma
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server