我正在尝试从数据库中获取数据。
这是我到目前为止所做的-
var getHistory = await MatchingPetsModel
.query()
.select(raw("IF(sender_pet_id ='"+req.body.pet_id+"', receiver_pet_id, sender_pet_id) AS against_pet_id"))
.select(raw("IF(sender_pet_id ='"+req.body.pet_id+"', sender_status, receiver_status) AS new_status"))
.select(raw("IF(sender_pet_id ='"+req.body.pet_id+"', sender_updated, receiver_updated) AS new_date"))
.select(raw("IF(sender_pet_id ='"+req.body.pet_id+"', sender_pet_id, receiver_pet_id) AS own_pet_id"))
.select('sender_pet_id','receiver_pet_id','sender_status','receiver_status','receiver_updated')
.havingRaw('own_pet_id =' + req.body.pet_id)
.where(function(queryBuilder){
if(queryNo == 2){
queryBuilder.having(raw("date(new_date)") ,"=", currentDate);
}
});
但是它不起作用。如何在Objection.js中使用hadRaw
任何帮助将不胜感激。
谢谢。