1
I am doing a put route to update, and using knexJS to update the data in the database, and in my code the solution I found was this below:
dbKnex("game").where({ id: id }).select("*").then(data => {
if(data != "") {
var { nome, preco } = req.body;
dbKnex("game").where({ id: id }).update({ nome: nome, preco: preco}).then(data => {
res.sendStatus(200);
}).catch(err => {
console.log(err);
})
} else {
res.sendStatus(404);
}
})
In this first search of the database it returns the data that was found in a select, which are then used in a check if they exist in the database (if(data != "")
), but I want another solution that doesn’t need that select, only one condition on the WHERE part.