按字段组合对筛选器进行Sequelize



我有一个地址表,它包含字段:{AddressLine1, City, State, Zip}

我想通过这些字段的组合进行筛选,以便只有在以下条件匹配时才返回结果:

searchKeyword是(AddressLine1+"+城市+","+州+"+zip(的子集

addressLine1 = 2384  River Road
city = Colorado springs
state = CO
zip = 80918
desired combination = 2384  River Road Colorado springs, CO 80918
return record if the searchKeyword is subset of desired combination. 
e.g.["River Road Colorado", "CO 80918", "springs, CO"]
sql wise => desiredCombination like '%searchKeyword%'

我查看了sequelize文档,并掌握了使用[Op.or] [Op.and]和其他运算符进行复杂过滤的方法。

我还查看了Complex,其中顶层的条款

但我在文档中找不到任何与我想做什么相关的内容。

我目前拥有的:

model.findAll({
where: { addressLine1: { [Op.like]: `%${searchKeyword}%` } }
})

如果可能的话,我不想使用原始查询。谢谢

您可以按如下方式构造where子句-

where: {
[op.and]: [Sequelize.literal('concat (addressLine1,city,state,zip) LIKE ${searchKeyword} )')]
},

希望它能有所帮助!

最新更新