【发布时间】:2020-06-11 20:47:49
【问题描述】:
router.get("/stocks/authed/:symbol", function (req, res, next) {
req.db
.from("stocks")
.select("*")
.modify(function(queryBuilder) {
if (req.query.from && req.query.to) {
queryBuilder.whereBetween('timestamp',[`%${req.query.from}%`,`%${req.query.to}%`]);
}
})
.where("symbol", "=", req.params.symbol)
.then((rows) => {
res.json({ Error: false, Message: "Success", Cities: rows })
})
.catch((err) => {
console.log(err)
res.json({ Error: true, Message: "Error in MySQL query" })
})
})
这是我现在得到的代码,网址是 http://localhost:3000/stocks/authed/AAL?from=2020-03-15T00%3A00%3A00.000Z&to=2020-03-20T00%3A00%3A00.000Z
为了允许中间人正确读取 url,我认为我需要使用 decodeuricomponent 解码 url
我该怎么做?我试过包围%${req.query.from}%,%${req.query.to}%,但没有奏效...
【问题讨论】:
-
不确定该日期格式,但我很确定
queryBuilder回调需要return一些东西 -
@ChrisG 无需从这些回调中返回任何内容。
标签: javascript mysql node.js express knex.js