Skip to content

Commit

Permalink
fix: create single instance for prisma client
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Oct 17, 2022
1 parent 7aac2ef commit 879250c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/server/db/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { PrismaClient } from '@prisma/client';

export const prisma = new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
});
declare global {
// allow global `var` declarations
// eslint-disable-next-line no-var, vars-on-top
var prisma: PrismaClient | undefined;
}

export const prisma =
global.prisma ||
new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
});

if (process.env.NODE_ENV !== 'production') global.prisma = prisma;

0 comments on commit 879250c

Please sign in to comment.