/* Code for Pagination */
let limit = 4; // number of records per page
let offset = 0;
let countallCompanies = 1000;
let page = req.body.page; // 1 by default page number
let order_by = req.body.order_by; // id by default
let order_by_ASC_DESC = req.body.order_by_ASC_DESC; // ASC by default
let pages = Math.ceil(countallCompanies.count / limit);
offset = limit * (page - 1);
/* End code for Pagination */
[err, companies] = await to(Company.findAll({
where: { company_name: { like: '%'+ req.body.q +'%' } },
limit: limit,
offset: offset,
order: [[order_by, order_by_ASC_DESC]]
}));
我希望续集会生成此查询:
SELECT * FROM `Companies` AS `Company` WHERE company_name LIKE '%aa%' ORDER BY `Company`.`id` ASC LIMIT 0, 4
相反,它生成以下查询:
SELECT * FROM `Companies` AS `Company` ORDER BY `Company`.`id` ASC LIMIT 0, 4
即使其他子句类似WHERE
,ORDER BY
等,也不会将LIMIT
条件添加到查询中。我尝试同时使用like
和{{ 1}},但两者均无效。如果我添加$like
,则会出现where: { id: 53 }
子句。
答案 0 :(得分:2)
在文件开始处添加const Op = Sequelize.Op;
。
有两种使用like的方式。 $like: [Op.like]
。
也可以尝试使用硬编码值,以查看数据是否正常。