[英]how to get data from mysql in node.js
I don't know what is the problem.. 我不知道是什么问题。
This code has 'SyntaxError: Unexpected identifier' err in line 14. 该代码在第14行中显示“ SyntaxError:意外的标识符”错误。
What is the problem between query and database pool? 查询和数据库池之间有什么问题?
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;
You are using await
(line 14) but the function is not async
. 您正在使用
await
(第14行),但是该函数不是async
。
just updated your route definition in this way 刚刚以这种方式更新了路线定义
router.get('/:user_id', async(req, res) => {
// your code
});
and it should work properly. 它应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.