【问题标题】:pgpromise insert return message failed, but successfully inserted into tablepg promise insert 返回消息失败,但成功插入到表中
【发布时间】:2021-10-07 05:07:42
【问题描述】:

pg-promise 成功地将一行插入到表中,但没有显示插入返回记录。 如果我不使用returning,那么一切都很好。如果使用则发生错误。

const createEMP = async (req, res, next) => {
try{
   let user = await db.none("insert into emp (name, salary, joindate) 
   values ( ${name}, ${salary}, ${joindate}) returning * ", req.body)

            res.status(200).json({
                user,
                "message": "new user created"
            })
        }
        catch(error) {next(error)}
    }

在邮递员中,它显示了很长的错误页面。它说:<pre>QueryResultError: No return data was expected.<br>.....

【问题讨论】:

  • API for the method 没有清楚地解释该方法期望的结果吗? -expects no data to be returned。只需阅读文档并遵循它。

标签: pg-promise


【解决方案1】:

db.none 更改为 db.one 工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-05
    • 2021-08-14
    • 2018-04-24
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多