我要在路由器的当前查询中添加另一个参数。
但我收到此错误:
TypeError:cb不是函数
在Query.client.query [作为回调]
这是我的代码:
// old code with just distance params that works
...
const express = require('express');
const pool = require('../modules/pool');
const router = express.Router();
router.get('/:lat/:lon', (req, res) => {
console.log('location GET local route');
let queryText = `SELECT *, distance($1, $2, location.latitude, location.longitude) as distance FROM location ORDER BY distance ;`
pool.query(queryText, [req.params.lat, req.params.lon]).then((result) => {
res.send(result.rows);
// console.log(result.rows)
}).catch((error) => {
console.log(error);
res.sendStatus(500);
});
});
module.exports = router;
// this is the current router with the error.
const express = require('express');
const pool = require('../modules/pool');
const router = express.Router();
router.get('/:lat/:lon/:type', (req, res) => {
console.log('location GET local route');
let queryText = `SELECT *, distance($1, $2, location.latitude, location.longitude) as distance FROM location ORDER BY distance WHERE "type" = $1;;`
pool.query(queryText, [req.params.lat, req.params.lon], [req.params.type])// erroring here
.then((result) => {
res.send(result.rows);
// console.log(result.rows)
}).catch((error) => {
console.log(error);
res.sendStatus(500);
});
});
module.exports = router;
答案 0 :(得分:0)
尝试更改
pool.query(queryText, [req.params.lat, req.params.lon], [req.params.type])
到
pool.query(queryText, [req.params.lat, req.params.lon, req.params.type])