Skip to content

Commit

Permalink
Merge pull request #8 from dylants/prisma-client
Browse files Browse the repository at this point in the history
chore: update prisma client loader
  • Loading branch information
dylants authored Jan 22, 2024
2 parents 433abe9 + 1721333 commit 9829097
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/lib/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// https://www.prisma.io/docs/orm/more/help-and-troubleshooting/help-articles/nextjs-prisma-client-dev-practices

import { PrismaClient } from "@prisma/client";

let prisma: PrismaClient;
const prismaClientSingleton = () => {
return new PrismaClient();
};

if (process.env.NODE_ENV === "production") {
prisma = new PrismaClient();
} else {
// @ts-ignore
if (!global.prisma) {
// @ts-ignore
global.prisma = new PrismaClient();
}
// @ts-ignore
prisma = global.prisma;
declare global {
var prisma: undefined | ReturnType<typeof prismaClientSingleton>;
}

const prisma = globalThis.prisma ?? prismaClientSingleton();

export default prisma;

if (process.env.NODE_ENV !== "production") globalThis.prisma = prisma;

0 comments on commit 9829097

Please sign in to comment.