【问题标题】:Knex data not inserting postgresKnex 数据未插入 postgres
【发布时间】:2015-12-12 20:29:40
【问题描述】:

我有以下 POST 路由将数据插入我的 postgres 数据库:

router.post('/add', function(req, res) {
console.log('add route hit at ' + currentDate);
console.log(req.body);

knex('users').insert(
    {first_name: req.body.first_name},
    {last_name: req.body.last_name}
)
});

由于某种原因,这不会将数据插入我的数据库,但也不会返回任何错误。有人可以帮忙吗?

谢谢!!

【问题讨论】:

  • 你试过 knex('users').insert( {first_name: req.body.first_name, last_name: req.body.last_name} )
  • 嗨 - 是的,但这也不起作用..

标签: javascript node.js postgresql orm


【解决方案1】:

你需要在knex链上调用then

router.post('/add', function (req, res) {
  return knex('users')
    .insert(req.body)
    .then(function () {
      res.send('welcome') // or something
    })
})

【讨论】:

    猜你喜欢
    • 2017-06-14
    • 2015-05-09
    • 1970-01-01
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 2018-11-25
    • 2021-03-16
    • 1970-01-01
    相关资源
    最近更新 更多