if you knew any thing about promise,or async/await
exports.getCategory=function(id){
return new Promise((resolve,reject)=>{
db.query("SELECT * FROM category_general =?",id, function(err, category){
if(err) reject(err);
resolve(category);
});
})
}
then,use await to get the result:
async function getQuery(){
//your code or something else
try{
let result = await getCategory(id);
// you can now use result
}catch(e){
//solve error
}
}
OOOOOR,to be easy :
exports.getCategory=function(id,callback){ //place a Func to solve the category
db.query("SELECT * FROM category_general =?",id, callback));
})
}
//then use like this:
//some code .....
getCategory(id,function(err,category){
if(err) {
//.....
}else{
//your code to do with category
}
});