async function connect() { if (global.connection && global.connection.state !== 'disconnected') return global.connection; const host = process.env.HOST; const port = process.env.PORT; const database = process.env.DATABASE; const user = process.env.DB_USER; const password = process.env.DB_PASSWORD; const mysql = require("mysql2/promise"); const connection = await mysql.createConnection("mysql://" + user + ":" + password + "@" + host + ":" + port + "/" + database + ""); console.log("Connected to MySQL!"); global.connection = connection; return connection; } async function getProducts() { const conn = await connect(); const [rows] = await conn.query('CALL catalogue_get("2024-01-30", "08001")'); return rows; } module.exports = { getProducts }