postman 查询失败错误:错误报告无效错误:列'user_id'不能为空

sdnqo3pr  于 2022-11-07  发布在  Postman
关注(0)|答案(1)|浏览(265)

我有3个文件:控制器、服务和dao。我想做函数readPost,但当使用postman时,它似乎卡在postDao内部的createPost函数中。请帮助我。
数据访问对象

const createPost = async (user_id, contents, posting_id, image_url) => {

  await myDataSource.query(
    `INSERT INTO postings ( user_id, contents ) 
    VALUE (?, ?)`,
    [user_id, contents]
  ),

  const post = await myDataSource.query(
    `INSERT INTO posting_images ( posting_id, image_url )
    VALUE (?, ?)`,
    [posting_id, image_url]
  );
  return post;
};

const readPost = async () => {

  const postings = await myDataSource.query(
    `SELECT 
      p.user_id, u.profile_image, 
      p_i.posting_id, p_i.image_url, p.contents
    FROM users u
    JOIN postings p
    ON u.id = p.user_id
    JOIN posting_images p_i
    ON p.id = p_i.posting_id`
  );
  return postings;
};

module.exports = { createPost, readPost };
csga3l58

csga3l581#

你能这样试试吗?
参考mySQL insert

const createPost = async (user_id, contents, posting_id, image_url) => {

  await myDataSource.query(
    `INSERT INTO postings ( user_id, contents ) 
    VALUES (?, ?)`,
    [user_id, contents]
  ),

  const post = await myDataSource.query(
    `INSERT INTO posting_images ( posting_id, image_url )
    VALUES (?, ?)`,
    [posting_id, image_url]
  );
  return post;
};

相关问题