31 lines
757 B
TypeScript
31 lines
757 B
TypeScript
// src/config/db.ts
|
|
import mysql from 'mysql2/promise';
|
|
import config from './config';
|
|
import logger from '../utils/logger';
|
|
|
|
const pool = mysql.createPool({
|
|
host: config.db.host,
|
|
user: config.db.user,
|
|
password: config.db.password, // Make sure this is being passed
|
|
database: config.db.database,
|
|
port: config.db.port,
|
|
connectionLimit: config.db.connectionLimit,
|
|
waitForConnections: true,
|
|
queueLimit: 0
|
|
});
|
|
|
|
// Test connection
|
|
pool.getConnection()
|
|
.then(connection => {
|
|
logger.info('Database connected successfully');
|
|
connection.release();
|
|
})
|
|
.catch(error => {
|
|
logger.error('Database connection failed:', {
|
|
message: error.message,
|
|
code: error.code,
|
|
errno: error.errno
|
|
});
|
|
});
|
|
|
|
export default pool; |