Javascript Sequelize:搜索不区分大小写的子字符串
我在路由中收到一个名称,我想搜索字符串中的子字符串,但不区分大小写。我当前的代码可以工作,但它区分大小写Javascript Sequelize:搜索不区分大小写的子字符串,javascript,node.js,sequelize.js,Javascript,Node.js,Sequelize.js,我在路由中收到一个名称,我想搜索字符串中的子字符串,但不区分大小写。我当前的代码可以工作,但它区分大小写 if(name){ specifications = { ...specifications, where: { name: { [Sequelize.Op.substring]: name } } } } 我的表中有两条记录: { "id": 8, "name": "Ementas", &
if(name){
specifications = {
...specifications,
where: { name: { [Sequelize.Op.substring]: name } }
}
}
我的表中有两条记录:
{
"id": 8,
"name": "Ementas",
"tabId": 1,
"createdAt": "2020-06-24T19:56:53.116Z",
"updatedAt": "2020-06-24T19:56:53.116Z",
"user": null,
"documents": []
},
{
"id": 6,
"name": "Eu",
"tabId": 1,
"createdAt": "2020-06-24T19:56:47.324Z",
"updatedAt": "2020-06-24T19:56:47.324Z",
"user": null,
"documents": []
},
如果搜索“e”,则只返回第一条记录,但如果搜索“e”,则返回两条记录
如何使Op.substring不敏感
ps:我正在使用postgres使用
iLike
操作符而不是子字符串
:
if(name){
specifications = {
...specifications,
where: { name: { [Sequelize.Op.iLike]: `%${name}%` } }
}
}