mirror of
https://github.com/BradNut/weddingsite
synced 2025-09-08 17:40:36 +00:00
20 lines
461 B
TypeScript
20 lines
461 B
TypeScript
|
|
import { PrismaClient } from "@prisma/client";
|
||
|
|
|
||
|
|
const prismaClientSingleton = () => {
|
||
|
|
return new PrismaClient();
|
||
|
|
};
|
||
|
|
|
||
|
|
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
|
||
|
|
|
||
|
|
const globalForPrisma = globalThis as unknown as {
|
||
|
|
prisma: PrismaClientSingleton | undefined;
|
||
|
|
};
|
||
|
|
|
||
|
|
const prisma = globalForPrisma.prisma ?? prismaClientSingleton();
|
||
|
|
|
||
|
|
export default prisma;
|
||
|
|
|
||
|
|
if (process.env.NODE_ENV !== "production") {
|
||
|
|
globalForPrisma.prisma = prisma;
|
||
|
|
}
|