如何解决序列化查询准备问题
我有以下原始查询,需要转换为Sequelize ORM查询
在
count
和user_posts
的ASuser_posts
中选择count(*) (user_posts
。source_id
='621'和user_posts
。source_type
= 'game'ANDuser_posts
。user_id
= 87 ANDuser_posts
。post_type_id
= 7 ANDuser_posts
。archive
= false)或user_posts
。local_db_path
='xxx-xxx-xxx';
我已经在Sequelize ORM中编写了以下查询
let result = await Post.count({
where:{
local_db_path:local_db_path,[Op.or]:[
{
[Op.and]:[
{ source_id:inputs.source_id },{ source_type:MAP_SOURCE_TYPE[inputs.source_type] },{ user_id:user.id },{ post_type_id:7 },{ archive:false },]
}
]
}
});
但是此查询在local_db_path和花括号条件之间添加了AND操作,但是我需要OR运算符而不是AND。
解决方法
您必须将local_db_path
移至Op.or案例:
let result = await Post.count({
where: {
[Op.or]: [
{
[Op.and]: [
{ source_id: inputs.source_id },{ source_type: MAP_SOURCE_TYPE[inputs.source_type] },{ user_id: user.id },{ post_type_id: 7 },{ archive: false },],},{
local_db_path: 'xxx-xxx-xxx',});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。