Closed burhanahmeed closed 1 year ago
This happen quite sometimes, how do I reconnect automatically when the connection lost?
I am using createPool
createPool
const connection = await mysql .createPool({ user: DB_USER || dbUser, password: DB_PASS || dbPass, database: DB_DATABASE || dbDatabase, host: DB_HOST || dbHost, port: DB_PORT || 3306, ...config, }) .catch((err) => { throw customError(err); });
and pass the connection to helper function to execute the query
export const executeSQL = async (sql: string, type: string, conn: Pool): Promise<any> => { try { const results = await conn.query(sql); return results; } catch (error) { console.log(error); throw error; } };
Use the reconnect option mentioned in the readme: https://github.com/CodeFoodPixels/node-promise-mysql#connectionoptions-object
This happen quite sometimes, how do I reconnect automatically when the connection lost?
I am using
createPool
and pass the connection to helper function to execute the query