From 510d47c07a93db7e754b55a7ebec382b1f7f3b6c Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Wed, 12 Oct 2022 23:09:42 +0200 Subject: [PATCH] use global for prisma --- db/index.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/db/index.ts b/db/index.ts index 4619a9a..1fd26d4 100644 --- a/db/index.ts +++ b/db/index.ts @@ -1,11 +1,23 @@ import { BookingStatus, Booking, PrismaClient, Prisma } from '@prisma/client' -const prisma = new PrismaClient() - import { getBookedDays as calendarGetBookedDays } from '../lib/googlecalendar' import { uniqueFilter } from '../helpers/array' import { dateFormatBackend, getDays, nowInTz } from '../helpers/date' +declare global { + // allow global `var` declarations + // eslint-disable-next-line no-var + var prisma: PrismaClient | undefined +} + +export const prisma = + global.prisma || + new PrismaClient({ + log: ['query'], + }) + +if (process.env.NODE_ENV !== 'production') global.prisma = prisma + export async function getBookedDays( uuidsToIngore?: string[] ) {