When I do a select in my MYSQL , I get the answer and I can display this for the user, but the problem is that this is not enough, just get the result and display it, I need to, for example, check if a given id has data in a table, and if it does not have it, do INSERT .
This is my code on the server side.
app.post('/companies', function(req, res) {
console.log('enviado do app'+req.body.id);
let filter = '';
filter = ' WHERE id_companies=' + req.body.id;
execSQLQuery('SELECT * FROM companies' + filter, res);
"é aqui que eu preciso usar a variável results que eu recebo lá embaixo para continuar"
});
//inicia o servidor
app.listen(port);
console.log('API funcionando!');
function execSQLQuery(sqlQry, res){
const connection = mysql.createConnection({
host : '***************',
port : 1111,
user : '**************',
password : '************',
database : '****************'
connection.query(sqlQry, function(error, results, fields){
if(error)
res.json(error);
else
res.json(results);
connection.end();
console.log('executou!');
});
}
If anyone can help me thank you too much.