cal/packages/prisma/index.ts
Agusti Fernandez Pardo 22460a460b
feat: Adds new customPrisma for hosted API (#3055)
* feat: customPrisma for hosted API access

* fix: 24h not 24 days for expiry cache in customPrisma calls

* fix: move PRISMA_CLIENT_CACHING_TIME to API

Co-authored-by: Agusti Fernandez Pardo <git@agusti.me>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-06-14 17:11:39 +00:00

28 lines
779 B
TypeScript

import { Prisma, PrismaClient } from "@prisma/client";
import { bookingReferenceMiddleware } from "./middleware";
declare global {
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}
const prismaOptions: Prisma.PrismaClientOptions = {};
if (!!process.env.NEXT_PUBLIC_DEBUG) prismaOptions.log = ["query", "error", "warn"];
export const prisma = globalThis.prisma || new PrismaClient(prismaOptions);
export const customPrisma = (options: Prisma.PrismaClientOptions) =>
new PrismaClient({ ...prismaOptions, ...options });
if (process.env.NODE_ENV !== "production") {
globalThis.prisma = prisma;
}
// If any changed on middleware server restart is required
bookingReferenceMiddleware(prisma);
export default prisma;
export * from "./selects";