chore: initial import to Nexus_Edu
This commit is contained in:
35
src/lib/db.ts
Normal file
35
src/lib/db.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
// This file would typically use mysql2/promise
|
||||
// import mysql from 'mysql2/promise';
|
||||
|
||||
// Mock DB Configuration storage (In-memory for demo, use env vars in prod)
|
||||
let dbConfig = {
|
||||
host: 'localhost',
|
||||
port: 3306,
|
||||
user: 'root',
|
||||
password: '',
|
||||
database: 'edunexus'
|
||||
};
|
||||
|
||||
// Mock Connection Pool
|
||||
export const db = {
|
||||
query: async (sql: string, params?: any[]) => {
|
||||
// In a real app:
|
||||
// const connection = await mysql.createConnection(dbConfig);
|
||||
// const [rows] = await connection.execute(sql, params);
|
||||
// return rows;
|
||||
|
||||
console.log(`[MockDB] Executing SQL: ${sql}`, params);
|
||||
return [];
|
||||
},
|
||||
testConnection: async (config: typeof dbConfig) => {
|
||||
// Simulate connection attempt
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
if (config.host === 'error') throw new Error('Connection timed out');
|
||||
|
||||
// Update active config
|
||||
dbConfig = config;
|
||||
return true;
|
||||
},
|
||||
getConfig: () => dbConfig
|
||||
};
|
||||
Reference in New Issue
Block a user