node.js - Sequelize 原始查询未正确打印
问题描述
我正在尝试在 sequelize 中编写查询,但查询不起作用下面是我在 sequelize 中编写的查询
var homePosts = db.postbox.findAll({
where: {
user_id: {
$or: {
$eq: id,
$in: [id]
}
}
},
attributes: ["user_posts_id"],
limit: 5
});
return homePosts;
Node js打印结果查询
Executing (default): SELECT `user_posts_id` FROM `user_posts_boxes` AS `user_posts_boxes` WHERE `user_posts_boxes`.`user_id` = '[object Object]' LIMIT 5;
[]
它打印对象而不是变量值并打印后续准备的实际查询。
我的实际原始查询如下,我实际上想将其转换为续集
SELECT `user_posts_id` FROM `user_posts_boxes` AS `user_posts_boxes` WHERE ( `user_posts_boxes`.`user_id` = '5' OR `user_posts_boxes`.`user_id` IN (select following_id from friend WHERE friend.follower_id = user_posts_boxes.user_id and friend.status='A' and friend.following_id=5)) LIMIT 5
解决方案
我对 Sequelize 5 有同样的问题。使用基于符号的运算符应该没问题https://github.com/sequelize/sequelize/issues/8417
推荐阅读
- javascript - 如何每秒向 Safari 中的微控制器 (ESP8266) 发送多达 50 个请求?
- matlab - 使用matlab删除长表中的重复行
- node.js - 使 KnexJS 事务与 async/await 一起工作
- javascript - 未使用 Google 登录从 Firebase 验证 id 令牌获取“电子邮件”
- python-3.x - 在多索引 Pandas 数据框中的表达式中使用其他变量创建新变量
- java - 9999之后如何继续生成这个系列(xyz*3)==zzz
- javascript - 如何在帧图像内渲染屏幕截图/图像而不会流过帧?
- oop - 在 Dart 中,是否可以在单例中传递参数?
- regex - RegEx 用于匹配除开头和结尾的重复字符之外的所有内容
- python-3.x - 在 Windows 上执行 PyInstaller 创建的包时出现 ModuleNotFound 错误