cal.pub0.org/lib/prisma.ts

15 lines
318 B
TypeScript
Raw Normal View History

2021-04-11 17:12:18 +00:00
import { PrismaClient } from '@prisma/client';
2021-03-22 13:48:48 +00:00
2021-04-11 17:12:18 +00:00
let prisma: PrismaClient;
2021-04-29 13:47:01 +00:00
const globalAny:any = global;
2021-03-22 13:48:48 +00:00
if (process.env.NODE_ENV === 'production') {
2021-04-11 17:12:18 +00:00
prisma = new PrismaClient();
2021-03-22 13:48:48 +00:00
} else {
2021-04-29 13:47:01 +00:00
if (!globalAny.prisma) {
globalAny.prisma = new PrismaClient();
2021-03-22 13:48:48 +00:00
}
2021-04-29 13:47:01 +00:00
prisma = globalAny.prisma;
2021-03-22 13:48:48 +00:00
}
2021-04-11 17:12:18 +00:00
export default prisma;