-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.ts
More file actions
33 lines (25 loc) · 1005 Bytes
/
db.ts
File metadata and controls
33 lines (25 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//import { PrismaClient, Prisma } from '@prisma/client'
import { PrismaClient, Prisma } from './../generated/prisma/client'
//import { withAccelerate } from '@prisma/extension-accelerate'
import { PrismaPg } from '@prisma/adapter-pg';
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
// Create a singleton instance of PrismaClient extended with accelerate.
const prismaClientSingleton = () => {
// Configure logging based on environment
const logConfig: Prisma.LogLevel[] =
process.env.NODE_ENV === 'development'
? ['error', 'warn'] // Only log errors and warnings in development
: ['error'] // Only log errors in production
return new PrismaClient({
log: logConfig,
adapter,
})
}
declare const globalThis: {
prismaGlobal: ReturnType<typeof prismaClientSingleton>
} & typeof global
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton()
if (process.env.NODE_ENV !== 'production') {
globalThis.prismaGlobal = prisma
}
export default prisma