My sequelize query always returns 0 results, but when I copy/paste the exact same query into psql it works fine, returning the correct rows exactly as expected
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 is an integer & today is a string of shape 'yyyy-mm-dd'
If I drop the 'today' condition, I get rows returned
Is sequelize escaping my date string?
If you defined named parameter like it fbid=:fbid
in the SQL script, you should pass an object {fbid: 'fbid_value'}
,
or if you defined unnamed parameters fbid=?
, you should pass an array ['fbid_value']
.
Here's docs http://docs.sequelizejs.com/en/latest/api/sequelize/#querysql-options-promise
Try to pass an object to replacement:
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 }
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.