clearSelect 不是函数 knex select 查询

clearSelect is not a function knex select query

我正在使用 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.12.8 中出现http://knexjs.org/#changelog

  • 添加了 clearSelect 和 clearWhere 来查询构建器 #1912