db.ts 506 B

12345678910111213141516
  1. /**
  2. * Singleton Prisma client instance.
  3. */
  4. import { PrismaClient } from '@prisma/client';
  5. // Global singleton to prevent multiple instances in development
  6. const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | undefined };
  7. export const prisma = globalForPrisma.prisma ?? new PrismaClient({
  8. log: process.env['LOG_LEVEL'] === 'debug' ? ['query', 'info', 'warn', 'error'] : ['warn', 'error'],
  9. });
  10. if (process.env['NODE_ENV'] !== 'production') {
  11. globalForPrisma.prisma = prisma;
  12. }