Spaces:
Runtime error
Runtime error
File size: 713 Bytes
24727a3 05cee1f 24727a3 05cee1f 24727a3 05cee1f 24727a3 05cee1f 24727a3 | 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 | import { PrismaClient } from '@prisma/client'
import { logger } from '../lib/logger.js'
const poolSize = parseInt(process.env.DATABASE_POOL_SIZE || '20', 10)
const globalForPrisma = globalThis
export const prisma = globalForPrisma.prisma ?? new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['query', 'error'] : ['error'],
transactionOptions: {
maxWait: 5000,
timeout: 10000,
},
})
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
export async function connectDB() {
try {
await prisma.$connect()
logger.info({ poolSize }, 'PostgreSQL connected')
} catch (err) {
logger.fatal(err, 'Database connection failed')
process.exit(1)
}
}
|