perf: Enable Prisma Optimize (#44)

* Enable Prisma Optimize

* Added Environment variable to toggle on and off the Prisma Optimize

---------

Co-authored-by: harshsbhat <icybhat@gmail.com>
This commit is contained in:
Harsh Shrikant Bhat
2024-08-01 02:05:14 +05:30
committed by GitHub
parent 75afd339ea
commit 0c072579b9
6 changed files with 311 additions and 15 deletions

View File

@@ -1,12 +1,18 @@
import { PrismaClient } from "@prisma/client";
import { withOptimize } from "@prisma/extension-optimize";
import { env } from "~/env";
const createPrismaClient = () =>
new PrismaClient({
const createPrismaClient = () => {
const client = new PrismaClient({
log:
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
});
if (env.ENABLE_PRISMA_CLIENT) {
return client.$extends(withOptimize());
}
return client;
};
// eslint-disable-next-line no-undef
const globalForPrisma = globalThis as unknown as {