node.js - Sequelize 返回错误的结果
问题描述
我将 sequelize 与 Postgresql 一起使用,如果我在 pgadmin postgresql 客户端中运行以下查询,我有正确的值:
select students->>'name', students->>'birthday', u.created_at
from users u, json_array_elements(u.information->'Section B') students
where u.created_at::date = '2019-08-01T00:00:00.000Z'
我的学生表是这样的:
id - serial2
students - json
created_at: timestamp with time zone
当我在 sequelize 中运行与以下相同的查询时,结果为空:
sequelize.query(`select students->>'name', students->>'birthday', u.created_at
from users u, json_array_elements(u.information->'Section B') students
where u.created_at::date = :created_at'`, {
type: sequelize.QueryTypes.SELECT,
replacements: {created_at: where_date }
和 where_date = 2019-08-01T00:00:00.000Z
在我的模型定义中,我timestamps: true
已经尝试使用timestamps: false
相同的空结果。
解决方案
就我而言,只是数据库配置不匹配,所以我在 pgadmin 中查询一个数据库并指向应用程序中的另一个数据库。很明显,但仍然值得一看凭据。
推荐阅读
- docker - docker compose 无法识别本地环境文件
- sql-server - 如何在 linux 中跟踪 mssql 服务器日志?
- angular - 是否可以在 Angular js 中使用 Angular 10 库?
- react-bootstrap - 使用 react-bootsrap 创建简单布局(页眉、正文、页脚)的最佳方法是什么?
- selenium - 当每次新页面加载时其 ID 更改时,如何使用 selenium 选择单选按钮组中的第一个选项
- flutter - 如何解决“位置参数过多:预期 1 个,但找到 3 个”。颤振问题
- android - 获取 API 26 之前 Android 上的共享库列表
- python - 如何阻止 matplotlib 跳过数据中的空白?
- web-scraping - 谁能帮我解释 youtube 工作室的 robots.txt 吗?
- machine-learning - 正确验证 allennlp 自动编码器