【发布时间】:2020-08-25 08:43:03
【问题描述】:
我有以下原始查询需要转换为 Sequelize ORM 查询
SELECT count(*) AS
countFROMuser_postsASuser_postsWHERE (user_posts.source_id= '621' 和user_posts.source_type= '游戏' 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。
【问题讨论】:
标签: node.js sequelize.js