Files
inventory/inventory-server/src/utils/db.js
2025-01-10 19:13:02 -05:00

21 lines
347 B
JavaScript

const mysql = require('mysql2/promise');
let pool;
function initPool(config) {
pool = mysql.createPool(config);
return pool;
}
async function getConnection() {
if (!pool) {
throw new Error('Database pool not initialized');
}
return pool.getConnection();
}
module.exports = {
initPool,
getConnection,
getPool: () => pool
};