我正在使用knex和bookshelf来执行多个where子句的查询。我有一个带有限制和偏移的过滤列表,我需要所有结果的总和,没有限制偏移。我正在尝试使用clearSelect
,但我一直收到错误,说明clearSelect不是函数。
我的代码
DoctorPayor
.query((qb) => {
qb.innerJoin('doctors', (joinTable) => {
joinTable.on('doctors_payors.doctor_id', '=', 'doctors.id')
.onNull('doctors_payors.deleted_at')
})
.innerJoin('practices', (joinTable) => {
joinTable.on('practices.id', '=', 'doctors.practice_id')
.onNull('practices.deleted_at')
})
.where('doctors_payors.onboarded_status', '=', requestParams.status)
.where('doctors_payors.payor_id', '=', payorId)
.where('practices.deleted_at', 'IS', null);
if(requestParams.speciality)
qb.where('doctors.speciality', '=', requestParams.speciality);
if(requestParams.locality)
qb.where('practices.location', '=', requestParams.locality);
if(requestParams.city)
qb.where('practices.city', '=', requestParams.city);
if(requestParams.score_min)
qb.where('doctors.recommendation_score', '>', requestParams.score_min);
if(requestParams.score_max)
qb.where('doctors.recommendation_score', '<', requestParams.score_max);
if(requestParams.consultation_min)
qb.where('doctors.consultation_fee', '>', requestParams.consultation_min);
if(requestParams.consultation_max)
qb.where('doctors.consultation_fee', '<', requestParams.consultation_max);
if(requestParams.doctor_name)
qb.where('doctors.name', 'like', '%' + requestParams.doctor_name + '%');
if(requestParams.practice_name)
qb.where('practices.name', 'like', '%' + req.query.practice_name + '%');
qb.limit(limit).offset(offset)
qb.select(
)
.then((response) => {
let responseObj = {};
responseObj.doctorsList = responseObj;
qb.clearSelect() /// <-- error is thrown here
qb.count('* as doctor_count')
.then((countResponse) => console.log(countResponse))
resolve(response)
})
.catch((error) => reject(error))
});
有人能告诉我,我做错了会有什么帮助。感谢
答案 0 :(得分:1)
此功能来自版本0.12.8 http://knexjs.org/#changelog