使用pg:7.5.0和node.js成功插入sql后,sql select不起作用

时间:2018-11-23 18:31:09

标签: node.js postgresql express pg

我的情况是一本书的复习部分。我已成功将数据插入数据库中,但是插入查询之后的选择查询未返回任何项目。我究竟做错了什么?请在下面找到一些代码以供参考。

reviewRouter.post('/:id', function (req, resp) {
    let orderId = req.body.orderId;
    let bookId = parseInt(req.params.id);
    let userRating = parseInt(req.body.clickedValue);
    let userReview = req.body.review;
    ratingNumber.push(userRating);

    var postresult = client.query("INSERT INTO public.review(order_id, book_id, review_rating, review_comment) VALUES($1,$2,$3,$4)", [orderId, bookId, userRating, userReview]);

    var commentsArray1 = [];
    client.query('SELECT r.book_id, r.review_comment, r.review_rating FROM review r',
      (err1, res1) => {
        for (i = 0; i < res1.rows.length; i++) {
          commentsArray1.push(
            {
              idofCommentedBook: res1.rows[i].book_id,
              comment: res1.rows[i].review_comment,
              rating: res1.rows[i].review_rating,
            });
        }
        //client.end();
      });

    const specificBookReview = books[bookId - 1];

    resp.render(
      'bookView',
      {
        nav,
        title: 'Library',
        book: specificBookReview,
        commentsArray: commentsArray
      }
    );
    client.end();
  });
  return reviewRouter;
}

0 个答案:

没有答案