I turn my code to class, it now return some error. that i dont know what is this. i tested already without wrapper into class, the code working. what is this exactly?
TypeError: (intermediate value) is not iterable
const mysql = require('mysql2');
const options = require('../config/database');
class Mysql
{
pool;
createPool(options)
{
this.pool = mysql.createPool(options).promise();
}
async execute(query, parameter)
{
try
{
const [rows,fields] = this.pool.execute(query, parameter);
return [rows,fields];
}catch(e)
{
console.log(e.code);
}
}
}
const client = new Mysql;
client.createPool(options);
(async () => {
const [rows] = await client.execute("SELECT * FROM media");
console.log(rows);
})();