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