0

My question is similar to this post but the solution didnt work for me probably because im using a different type of mysql connection (pool). This is my code:

    let config= {
        host: '***',
        user: 'admin',
        password: '***,
        port: '3306',
        database: '***',
        multipleStatements: true
    };

const con = mysql.createPool(config);
select();
function select(){
    return new Promise((resolve, reject) => {
        con.getConnection(function (err, connection) {
            if (err) throw err;
            else
                console.log("Connected!");
            let sql = "SELECT * FROM bidPrice WHERE idExchangePlatform = 2;";
            connection.query(sql, function (err, results, fields) {
                connection.release();
                connection.destroy();
                if (err) throw err;
                console.log(results)
                resolve(results);
            });

        });
    });
}

I also important to mention that im running this function using the following command

node --max-old-space-size=31744 index.js # Increase to 31 GB 

This is because im working with millions of records from the database query If i run this with regular node command i would be getting Javascript heap out of memory

When i tried integrating the solution i mentioned earlier to my code i just get a "killed" log after a while and then the process stops, should i handle server disconnect in a different way when using mysql.pool?

enter image description here

1 Answers1

0

If you have big table with many rows, you will must check index for column 'idExchangePlatform' and create if doesn't make it

And simple variant your code:

function select(){
    return new Promise((rs, rj) => {
        let sql = "SELECT * FROM bidPrice WHERE idExchangePlatform = 2;";
        pool.query(sql, (err, rows) => {
            if(err)
                return rj(err);
            return rs(rows);
        })
    });
}
ivani
  • 13
  • 4