gpt4 book ai didi

javascript - 在 where 子句中将强制转换列序列化为整数

转载 作者:搜寻专家 更新时间:2023-11-01 05:28:06 24 4
gpt4 key购买 nike

尝试在 where 子句中强制转换列以搜索查询。很难找到有关如何执行此操作的可靠文档。有什么想法吗?

return await User.findAndCountAll({
where: {
[Op.or]: {
'email': { [Op.iLike]: `%${query}%` },
'$id::text$': { [Op.iLike]: `%${query}%` } // id is int but needs to be string for searching
}
},
limit,
offset: page * limit,
order: [[sortBy, sortOrder.toUpperCase()]],
raw: true,
logging: console.log
});

最佳答案

我认为这就是您要搜索的内容:

where: {
[Op.or]: [
{email: {[Op.iLike]: `%${query}%`}},
sequelize.where(
sequelize.cast(sequelize.col('User.id'), 'varchar'),
{[Op.iLike]: `%${query}%`}
),
],
},

关于javascript - 在 where 子句中将强制转换列序列化为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47212187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com