mysql - Like Statement 在续集中对我不起作用
问题描述
你在做什么?
/* 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]]
}));
你期望会发生什么?
我希望 sequelize 生成这个查询:
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
and $like
,但都没有工作。如果我添加where: { id: 53 }
,则该WHERE
子句确实出现。
解决方案
const Op = Sequelize.Op;
在文件开头添加。
有两种使用like的方法。$like: [Op.like]
.
还可以尝试使用硬编码值来查看您的数据是否正常。
推荐阅读
- azure - Azure kubernetes - 带有内部负载均衡器的 Istio 控制器
- svg - AnimateMotion 路径在 Firefox 中不起作用
- macros - Julia:我如何在宏中使用 kwargs……?
- json - How do i create an object using a function from a list of nested maps parse from json in Flutter
- css - 无法让本地自定义字体与 Ubuntu 上的 Shiny App 一起使用
- html - 在抓取机器人上找不到下载文件的链接
- git - 如何有效地倒带和重播我在 git 中的更改?
- python - 如何将以下 matlab 代码转换为 python?
- python - 在 pandas 中快速申请
- git - 有没有办法将文件标记为“正在处理”?