Trung Tran
Trung Tran

Reputation: 13721

Knex data not inserting postgres

I have the following POST route to insert data into my postgres database:

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}
)
});

For some reason, this does not insert data into my database, but does not return any errors either. Can someone help?

Thank you!!

Upvotes: 1

Views: 1072

Answers (1)

thebearingedge
thebearingedge

Reputation: 681

You need to call then on the knex chain

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

Upvotes: 2

Related Questions