【问题标题】:Nodejs-PSQL-ILIKE searchNodejs-PSQL-ILIKE 搜索
【发布时间】:2020-02-12 09:33:15
【问题描述】:

我的问题是下一个。我想在单词内部搜索,但找不到解决方法。我尝试做这样的事情:

("%" + $2 + "%") 

错误通常是 $2 附近的语法错误或定义错误。

function getFilteredData(req, res, next) {
    var dataid = String(req.params.dataid);
    const pageSize = req.query.pageSize;
    const pageIndex = req.query.pageIndex;
    const offset = pageSize * pageIndex;
    const limit = pageSize;
    const filter = req.query.dataname;
    const commonParams = [country, `${filter}%`];
    db.any(
      'SELECT * FROM data WHERE dataid = $1 AND dataname ILIKE $2  ORDER BY isactive=true desc LIMIT $3 OFFSET $4',
      [...commonParams, limit, offset ]
    )
      .then(function (datas) {
        return db.one('SELECT COUNT(*) FROM data WHERE dataid = $1 AND data name ILIKE $2', commonParams).then(countResult => {
        res.status(200)
          .json({
            status: 'success',
            datas: data,
            totalItemsCount: countResult.count,
            message: 'Retrieved filtered Data'
          });
      })
    })
      .catch(function (err) {
        return next(err);
      });
  }

【问题讨论】:

    标签: node.js postgresql sql-like


    【解决方案1】:

    我找到了答案 -> 再取一个百分号 const commonParams = [国家,%${filter}%];

    【讨论】:

      猜你喜欢
      • 2015-02-11
      • 1970-01-01
      • 2018-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      • 2021-12-29
      • 2020-07-10
      相关资源
      最近更新 更多