如何编写多个查询,其中每个查询取决于先前查询的结果(sqlite)

时间:2019-02-16 01:12:18

标签: javascript sqlite

问题: 我有4个表格(项目,用户,评论和评论)。我需要根据商品名称获得评论,此查询很简单

SELECT * FROM Reviews WHERE item_id =(SELECT id FROM Items WHERE itemname=${itemname})

但是,根据 Reviews.id Reviews.author ,我需要从用户(用户名,头像等)和注释(正文,日期)中提取所有信息等)。不确定如何链接查询,然后将其格式化为所需格式

{
  id: "some id",
  date: "some date",
  author: 
    {id: "user id",
    avatar: "avatar url",
    username: "some username"},
  body: "review text",
  rating: "some number",
  item_id: "",
  comments: {
    id: "comments id",
    date: "comment date",
    author: {
      id: "user id",
      avatar: "avatar url",
      username: "some username"},
      replied_to_id: "",
  }
}

这怎么办?查询3个表并格式化数据,以便可以以

的形式发送数据

[
   {review1 with comments},
   {review2 with comments},
    ...,
   {reviewN with comments}
]

谢谢。

0 个答案:

没有答案