如何在node.js中从mysql获取数据

p1tboqfb  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(355)

我不知道有什么问题。。
此代码第14行有“syntaxerror:unexpected identifier”错误。
查询和数据库池之间存在什么问题?

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;
beq87vna

beq87vna1#

您正在使用 await (第14行)但函数不是 async .
刚刚用这种方式更新了你的路线定义

router.get('/:user_id', async(req, res) => {
   // your code
});

它应该能正常工作。

相关问题