router icon indicating copy to clipboard operation
router copied to clipboard

[feat] koa 相关库的介绍文档不够详细,如何使用

Open dong-lufei opened this issue 1 year ago • 1 comments

// 查询所有用户
router.get("/users", async (ctx, next) => {
  const sql = "SELECT * FROM users"
  connection.query(sql, (err, results, fields) => {
    if (err) {
      console.error(err)
      ctx.body = { success: false, message: "查询失败" }
      return
    }
    console.log("get", results)
    ctx.body = { success: true, data: results }
  })
})

我根路由都访问成功,这个路由咋404,但是数据库写进去了而且读成功,console 那行成功有正确数据

dong-lufei avatar Jun 04 '23 07:06 dong-lufei

哦,知道原因了,好像是 mysql 造成的。我把 npm i mysql 改用 npm i mysql2 就成功了

dong-lufei avatar Jun 04 '23 07:06 dong-lufei

@dong-lufei Happy to hear that you resolved the issue that you faced!

3imed-jaberi avatar Sep 18 '24 00:09 3imed-jaberi