-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from dylants/prisma-client
chore: update prisma client loader
- Loading branch information
Showing
1 changed file
with
11 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |