不知道问题出在哪里。
此代码在第 14 行出现“SyntaxError:意外标识符”错误。
查询和数据库池之间有什么问题?
const express = require('express');
const router = express.Router();
const request=require('async');
const db = require('../../module/pool.js');
router.get('/:user_id', (req, res) => {
try {
if(!(req.params.user_id)){
res.status(403).send({
message : "no user_id input"
});
} else {
let query = 'select A.store_name, A.store_img, count(B.store_idx) as review_cnt from board.store A Left Join board.review B On A.store_idx is B.store_idx where store_idx is (select A.store_idx from bookmark where user_id = ?)';
let bookmarks = await db.queryParam_Arr(query, [req.params.user_id]);
if (!bookmarks) {
res.status(500).send({
msg : "No Bookmarks"
});
} else {
res.status(200).send({
msg : "Successfully get list",
list : bookmarks
});
}
}
} catch (err) {
console.log(err);
res.status(500).sen ({
msg : "syntax err"
});
}
});
module.exports = router;
最佳答案
您正在使用 await
(第 14 行),但该函数不是 async
。
刚刚以这种方式更新了您的路线定义
router.get('/:user_id', async(req, res) => {
// your code
});
它应该可以正常工作。
关于mysql - 如何在node.js中从mysql获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50672982/