【问题标题】:Is it possible to use knex returning() method with PostgreSQL to return all the rows in an operated table是否可以在 PostgreSQL 中使用 knex 返回()方法来返回操作表中的所有行
【发布时间】:2019-04-14 03:15:13
【问题描述】:

是否可以在使用 Knex.js 使用返回方法插入一行后返回表中的所有行。我试过返回('*'),它只返回受影响的行,而不是表中的所有行。我使用 POSTGRESQL 作为我的数据库。请帮忙。

我的代码:

app.post('/create', (req, res) => {
  const { title, content } = req.body;
 db('projects').insert({
   title: title,
   content: content,
   authorfirstname: 'John',
   authorlastname: 'Doe',
   authorid: '12345',
   createdat: new Date()
 })
 .returning('*')
 .then( project => {res.json(project)})
 .catch( err => res.status(400).json('unable to add project'))
})

【问题讨论】:

    标签: javascript node.js postgresql knex.js


    【解决方案1】:

    没有。 PostgreSQL 不支持这样的东西。您需要先插入然后选择表格的所有行。

    【讨论】:

    • 也许downvoters 没有阅读这个问题。 2021 年仍然只返回受影响的行。
    猜你喜欢
    • 2013-10-16
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 2023-01-13
    • 1970-01-01
    相关资源
    最近更新 更多