Skip to content

Commit 804291a

Browse files
Added comments.
1 parent cd0b0b6 commit 804291a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/lib/db.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1+
// lib/prisma.ts
12
import { PrismaClient } from '@prisma/client'
23
import { withAccelerate } from '@prisma/extension-accelerate'
34

5+
// Create a singleton instance of PrismaClient extended with accelerate and logging.
46
const prismaClientSingleton = () => {
5-
return new PrismaClient().$extends(withAccelerate())
7+
return new PrismaClient({
8+
log: ['query'],
9+
}).$extends(withAccelerate())
610
}
711

12+
// Use a global variable to persist the Prisma Client across hot reloads in development.
813
declare const globalThis: {
914
prismaGlobal: ReturnType<typeof prismaClientSingleton>
1015
} & typeof global
1116

1217
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton()
1318

14-
export default prisma
19+
if (process.env.NODE_ENV !== 'production') {
20+
globalThis.prismaGlobal = prisma
21+
}
1522

16-
if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma
23+
export default prisma

0 commit comments

Comments
 (0)