stacker.news/api/models/index.js

21 lines
536 B
JavaScript
Raw Normal View History

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({
log: [{ level: 'query', emit: 'event' }, 'warn', 'error']
})
2022-04-27 22:06:42 +00: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 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