Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let mysqlConnection = getFreeConnection();
- function getFreeConnection() {
- pool = getConnectionsPool();
- try {
- pool.getConnection(function cb(err, connection) {
- if (err) {
- console.error(`error getting connection from pool; ${err}`);
- throw err;
- }
- if (!connection) {
- console.error(`error getting connection from pool`);
- }
- return connection;
- });
- } catch (e) {
- console.error(e);
- }
- }
- function getConnectionsPool() {
- pool = pool ?
- pool :
- mysql.createPool({
- host: process.env.MYSQL_HOST,
- user: process.env.MYSQL_USER,
- password: process.env.MYSQL_PASSWORD,
- database: process.env.MYSQL_DB
- });
- if (!pool) {
- console.error(`error getting connections pool`);
- return null;
- }
- return pool;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement