是否可以在使用 Knex.js 的返回方法插入一行后返回表中的所有行。我试过 returning('*') ,它只返回受影响的行而不是表中的所有行。我使用 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'))
})
最佳答案
没有。 PostgreSQL 不支持类似的东西。您需要先插入然后选择表格的所有行。
关于javascript - 是否可以在 PostgreSQL 中使用 knex returning() 方法返回操作表中的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55638750/