diff --git a/packages/api/src/router/chats.ts b/packages/api/src/router/chats.ts index bfc50a354..403dc29fb 100644 --- a/packages/api/src/router/chats.ts +++ b/packages/api/src/router/chats.ts @@ -1,3 +1,4 @@ +import { prisma } from "@oakai/db/client"; import * as Sentry from "@sentry/nextjs"; import { TRPCError } from "@trpc/server"; import { isTruthy } from "remeda"; diff --git a/packages/db/client/index.ts b/packages/db/client/index.ts index 636ff043f..d8ed202f6 100644 --- a/packages/db/client/index.ts +++ b/packages/db/client/index.ts @@ -29,21 +29,16 @@ const createPrismaClient = () => { const extendedPrisma = createPrismaClient(); export type PrismaClientWithAccelerate = typeof extendedPrisma; -declare global { - // allow global `var` declarations - // eslint-disable-next-line no-var - var prisma: PrismaClientWithAccelerate | undefined; -} - -let prisma: PrismaClientWithAccelerate; - -if (process.env.NODE_ENV === "production") { - prisma = createPrismaClient(); -} else { - if (!global.prisma) { - global.prisma = createPrismaClient(); +let prismaInstance: PrismaClientWithAccelerate | undefined = undefined; + +const getPrismaClient = () => { + if (prismaInstance) { + return prismaInstance; } - prisma = global.prisma; -} -export { prisma }; + prismaInstance = createPrismaClient(); + + return prismaInstance; +}; + +export const prisma = getPrismaClient();