Refactor database access by introducing prisma.lambda.service for centralized PrismaClient usage across modules. Update imports in various handlers and services to utilize the new service, ensuring consistent database interactions and improved maintainability.
This commit is contained in:
22
src/common/database/prisma.lambda.service.ts
Normal file
22
src/common/database/prisma.lambda.service.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
|
||||
const adapter = new PrismaPg({
|
||||
connectionString: process.env.DATABASE_URL!,
|
||||
});
|
||||
|
||||
let prisma: PrismaClient;
|
||||
|
||||
if (!(global as any).prisma) {
|
||||
(global as any).prisma = new PrismaClient({
|
||||
adapter,
|
||||
log:
|
||||
process.env.NODE_ENV === 'dev'
|
||||
? ['query', 'info', 'warn', 'error']
|
||||
: ['error'],
|
||||
});
|
||||
}
|
||||
|
||||
prisma = (global as any).prisma;
|
||||
|
||||
export const prismaClient = prisma;
|
||||
Reference in New Issue
Block a user