Can anyone help me out why my function returning undefined? Here is my function
async function getPlaceIDByPincode(city, state, pincode)
{
let sql = "select * from place_master where pincode='"+pincode+"'";
await db.query(sql,(err,data)=>{
if(data.length)
{
return data[0].id;
}
else
{
let query = `INSERT INTO place_master
(city,state, pincode) VALUES (?,?,?);`;
let values = [
city.toUpperCase(), state.toUpperCase(),pincode
];
db.query(query,values, (err,rows)=>{
if(err)
{
console.log("Hii");
if(err.code=="ER_DUP_ENTRY")
{
return false;
}
}
return rows.insertId;
});
}
});
}
Here is function calling
getPlaceIDByPincode(city,state,pincode).then(function(result){
console.log(result); // returning undefined
});