File tree 1 file changed +10
-3
lines changed
1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change
1
+ // lib/prisma.ts
1
2
import { PrismaClient } from '@prisma/client'
2
3
import { withAccelerate } from '@prisma/extension-accelerate'
3
4
5
+ // Create a singleton instance of PrismaClient extended with accelerate and logging.
4
6
const prismaClientSingleton = ( ) => {
5
- return new PrismaClient ( ) . $extends ( withAccelerate ( ) )
7
+ return new PrismaClient ( {
8
+ log : [ 'query' ] ,
9
+ } ) . $extends ( withAccelerate ( ) )
6
10
}
7
11
12
+ // Use a global variable to persist the Prisma Client across hot reloads in development.
8
13
declare const globalThis : {
9
14
prismaGlobal : ReturnType < typeof prismaClientSingleton >
10
15
} & typeof global
11
16
12
17
const prisma = globalThis . prismaGlobal ?? prismaClientSingleton ( )
13
18
14
- export default prisma
19
+ if ( process . env . NODE_ENV !== 'production' ) {
20
+ globalThis . prismaGlobal = prisma
21
+ }
15
22
16
- if ( process . env . NODE_ENV !== 'production' ) globalThis . prismaGlobal = prisma
23
+ export default prisma
You can’t perform that action at this time.
0 commit comments