Hello,
I hope you’re doing well.
I work with express.js and mysql for this specific sql query I need to retrieve a table with associated data. When I do a test via postman (to check the proper functioning of the backend) the loading is extremely slow and does not display any data. The server does not display anything.
//db.js
const dotenv = require("dotenv");
dotenv.config();
const { Sequelize } = require("sequelize");
const sequelize = new Sequelize(
process.env.DATAB,
process.env.USER,
process.env.PS,
{
dialect: "mysql",
host: "localhost",
}
);
try {
sequelize.authenticate();
console.log("Connect");
} catch (error) {
console.error("error");
}
sequelize.sync();
console.log("Good");
module.exports = sequelize;
//controllers.js
const db = require("../config.db/db");
exports.AllArticle = async (req, res) => {
try {
const articleComment = await db.query(
"SELECT * FROM articles left join comments on comments.ArticleId = articles._id",
(error, results, fields) => {
if (error) {
res.json({ error });
} else {
res.status(200).json({ results, articleComment });
}
}
);
} catch (error) {
res.status(500).json({ error });
}
};```