aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/prisma.ts
blob: 210e691dcb864c96eedf30ed01a8dd5d7ea74c71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { PrismaClient } from '@prisma/client'

let prisma: PrismaClient

export async function getPrisma() {
  if (!prisma) {
    if (process.env.NODE_ENV === 'production') {
      prisma = new PrismaClient()
    } else {
      if (!(global as any).prisma) {
        ;(global as any).prisma = new PrismaClient()
      }
      prisma = (global as any).prisma
    }
  }
  return prisma
}