gpt4 book ai didi

javascript - Sequelize 原始查询 : Valid SQL query returns nothing

转载 作者:行者123 更新时间:2023-12-03 22:41:48 26 4
gpt4 key购买 nike

我的 sequelize 查询总是返回 0 结果,
但是当我将完全相同的查询复制/粘贴到 psql 时它工作正常,完全按预期返回正确的行

  return sequelize.query(
"SELECT * FROM orders" +
" INNER JOIN sizes ON orders.sizeid = sizes.sizeid" +
" INNER JOIN types ON sizes.typeid = types.typeid" +
" INNER JOIN items ON types.itemid = items.itemid" +
" WHERE orders.fbid = :fbid AND pickuptime >= :today" +
" ORDER BY orders.pickuptime ASC",
{ replacements: {fbid, today}, type: sequelize.QueryTypes.SELECT }

);

fbid 是一个整数 & 今天是一个形状为 'yyyy-mm-dd' 的字符串

如果我放弃“今天”条件,我会得到返回的行

sequelize 是否转义了我的日期字符串?

最佳答案

如果您在 SQL 脚本中定义了类似 fbid=:fbid 的命名参数,
你应该传递一个对象 {fbid: 'fbid_value'}

或者如果你定义了未命名的参数 fbid=? ,你应该传递一个数组 ['fbid_value']

这是 http://docs.sequelizejs.com/en/latest/api/sequelize/#querysql-options-promise 文档

尝试将对象传递给替换:

return sequelize.query(
"SELECT * FROM orders" +
" INNER JOIN sizes ON orders.sizeid = sizes.sizeid" +
" INNER JOIN types ON sizes.typeid = types.typeid" +
" INNER JOIN items ON types.itemid = items.itemid" +
" WHERE orders.fbid = :fbid AND pickuptime >= :today" +
" ORDER BY orders.pickuptime ASC",
{ replacements: {fbid: 'fbid_value', today: 'today_value'}, type: sequelize.QueryTypes.SELECT }
);

关于javascript - Sequelize 原始查询 : Valid SQL query returns nothing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40276309/

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