21 lines
536 B
JavaScript
Raw Normal View History

2021-03-25 14:29:24 -05:00
import { PrismaClient } from '@prisma/client'
2022-04-27 17:06:42 -05:00
const prisma = global.prisma || (() => {
console.log('initing prisma')
const prisma = new PrismaClient({
log: [{ level: 'query', emit: 'event' }, 'warn', 'error']
})
2022-04-27 17:06:42 -05:00
prisma.$on('query', (e) => {
if (e.duration > 50) {
console.log('Query: ' + e.query)
console.log('Params: ' + e.params)
console.log('Duration: ' + e.duration + 'ms')
}
})
2022-04-27 17:06:42 -05:00
return prisma
})()
2021-03-25 14:29:24 -05:00
2022-04-27 17:06:42 -05:00
if (process.env.NODE_ENV === 'development') global.prisma = prisma
export default prisma