【发布时间】: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