fix: Complete automation v2 page runtime error fixes
- Fixed ES modules error by converting automation-with-learning-v2.js to pure ES6 - Fixed singleton pattern in automation-singleton.js for proper async handling - Fixed EnhancedAILearningPanel to handle recommendation objects correctly - Updated API routes to use correct import paths (../../../../lib/) - Created proper db.js utility with ES6 exports - Fixed simplified-stop-loss-learner imports and exports Automation v2 page now loads without errors AI learning system fully integrated and operational Learning status API working with detailed reports Recommendation rendering fixed for object structure
This commit is contained in:
42
lib/db.js
42
lib/db.js
@@ -1,46 +1,12 @@
|
||||
/**
|
||||
* Database utility for Prisma client
|
||||
*
|
||||
* Provides a global Prisma instance to avoid connection issues
|
||||
*/
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
let prisma;
|
||||
|
||||
// Global Prisma instance
|
||||
let prisma = null;
|
||||
|
||||
/**
|
||||
* Get the global Prisma database instance
|
||||
*/
|
||||
async function getDB() {
|
||||
function getDB() {
|
||||
if (!prisma) {
|
||||
prisma = new PrismaClient();
|
||||
|
||||
// Test the connection
|
||||
try {
|
||||
await prisma.$connect();
|
||||
console.log('✅ Database connection established');
|
||||
} catch (error) {
|
||||
console.error('❌ Database connection failed:', error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return prisma;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the database connection
|
||||
*/
|
||||
async function closeDB() {
|
||||
if (prisma) {
|
||||
await prisma.$disconnect();
|
||||
prisma = null;
|
||||
console.log('✅ Database connection closed');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getDB,
|
||||
closeDB
|
||||
};
|
||||
export { getDB };
|
||||
Reference in New Issue
Block a user