self-serve-integration-service
Version:
Self-Serve Integration Service for managing multiple funder integrations including REST APIs, SOAP APIs, and UI automation
69 lines (59 loc) • 1.42 kB
text/typescript
import { PrismaClient } from '@prisma/client';
import { logger } from '../utils/logger';
declare global {
// eslint-disable-next-line no-var
var __prisma: PrismaClient | undefined;
}
const prisma =
globalThis.__prisma ||
new PrismaClient({
log: [
{
emit: 'event',
level: 'query',
},
{
emit: 'event',
level: 'error',
},
{
emit: 'event',
level: 'info',
},
{
emit: 'event',
level: 'warn',
},
],
});
// Note: Prisma event listeners removed due to TypeScript compatibility issues
// Logging is handled through the Prisma client configuration above
// Graceful shutdown
process.on('beforeExit', async () => {
await prisma.$disconnect();
});
process.on('SIGINT', async () => {
await prisma.$disconnect();
process.exit(0);
});
process.on('SIGTERM', async () => {
await prisma.$disconnect();
process.exit(0);
});
// Test database connection
export async function testConnection(): Promise<boolean> {
try {
await prisma.$queryRaw`SELECT 1`;
logger.info('Database connection successful');
return true;
} catch (error) {
logger.error('Database connection failed:', error);
return false;
}
}
// Export prisma instance
export { prisma };
// Set global for hot reload in development
if (process.env.NODE_ENV === 'development') {
globalThis.__prisma = prisma;
}