I have a json request in this form:
{
"claimNo":["5454545","4554454","45884"]
}
the claimNo could hold any number of items(not restricted). I want to get the values and write a query to fetch data from a mysql db where claimNo = the values in the request. sample response:
"claims": [
{
"claimNo": "4554454",
"ClaimCause": "gjgiukhknl",
"ClaimAmount": 45550,
},
{
"claimNo": "5454545",
"ClaimCause": "fdfdfdfdf",
"ClaimAmount": 0,
}
]
I can successfully loop through the request and display on terminal or even insert into the db with multiple ORs but that only works for a restricted array length.
req.body.claimNo.forEach(element => {
// console.log(element)
let sql = 'SELECT * FROM claims WHERE claimNo = ?'
connection.query(sql,element,(err, rows, fields) => {
if(!err){
// return res.json({
// success:true,
// errorCode:"",
// errorDescription:"",
// claims:rows
// })
console.log(rows)
}else
console.log(err)
} )
})