I'm trying to upsert data to my database by doing an update query and if result.rowCount > 0
I console.log ('UPDATE Rows affected: ', result.rowCount);
else inserting . This is the code I'm copying from which uses async and a callback:
(async () => {
await client.query (updateQuery, (err, result)=>{
try {
if (err) throw err;
if (result.rowCount > 0){
console.log ('Rows affected: ', result.rowCount);
return;
} else {
client.query(insertQuery, (error, res) =>{
try {
if (error) throw error;
console.log ('Rows affected:', res.rowCount);
}catch(er){
console.log(er);
}finally {
//do something here
}
});
}
}catch (e){
console.log(e);
}
});
})().catch(e => console.log(e));
This code works if I'm trying to add it with the async and callback but how would I transform this to use .then?